Part Number Hot Search : 
FR107SG CXD2540Q LTC69 SG441020 1FW42 Z5241B CAMH9126 Z5241B
Product Description
Full Text Search
 

To Download ATTINY24V-10MUR Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  features ? high performance, low power avr ? 8-bit microcontroller ? advanced risc architecture ? 120 powerful instructions ? most single clock cycle execution ? 32 x 8 general purpose working registers ? fully static operation ? non-volatile program and data memories ? 2/4/8k bytes of in-system programmable program memory flash ? endurance: 10,000 write/erase cycles ? 128/256/512 by tes of in-system programmable eeprom ? endurance: 100,000 write/erase cycles ? 128/256/512 bytes of internal sram ? data retention: 20 years at 85 c / 100 years at 25 c ? programming lock for self-programming flash & eeprom data security ? peripheral features ? one 8-bit and one 16-bit timer/ counter with two pwm channels, each ? 10-bit adc ? 8 single-ended channels ? 12 differential adc channel pairs with programmable gain (1x / 20x) ? programmable watchdog timer with separate on-chip oscillator ? on-chip analog comparator ? universal serial interface ? special microcontroller features ? debugwire on-chip debug system ? in-system programmable via spi port ? internal and external interrupt sour ces: pin change in terrupt on 12 pins ? low power idle, adc noise reductio n, standby and power-down modes ? enhanced power-on reset circuit ? programmable brown-out detection circuit ? internal calibrated oscillator ? on-chip temperature sensor ? i/o and packages ? available in 20-pin qfn/ mlf & 14-pin soic and pdip ? twelve programmable i/o lines ? operating voltage: ? 1.8 ? 5.5v for attiny24v/44v/84v ? 2.7 ? 5.5v for attiny24/44/84 ? speed grade ? attiny24v/44v/84v ? 0 ? 4 mhz @ 1.8 ? 5.5v ? 0 ? 10 mhz @ 2.7 ? 5.5v ? attiny24/44/84 ? 0 ? 10 mhz @ 2.7 ? 5.5v ? 0 ? 20 mhz @ 4.5 ? 5.5v ? industrial temperature range: -40 c to +85 c ? low power consumption ? active mode (1 mhz system clock): 300 a @ 1.8v ? power-down mode: 0.1 a @ 1.8v 8-bit microcontroller with 2/4/8k bytes in-system programmable flash attiny24 attiny44 attiny84 rev. 8006k?avr?10/10
2 8006k?avr?10/10 attiny24/44/84 1. pin configurations figure 1-1. pinout attiny24/44/84 1.1 pin descriptions 1.1.1 vcc supply voltage. 1.1.2 gnd ground. 1.1.3 port b (pb3:pb0) port b is a 4-bit bi-directional i/o port with inte rnal pull-up resistors (selected for each bit). the port b output buffers have symmetrical drive characteristics with both high sink and source capability except pb3 which has the reset capability. to use pin pb3 as an i/o pin, instead of reset pin, program (?0?) rstdisbl fuse. as inpu ts, port b pins that are externally pulled low will source current if the pull-up resistors are activated. the port b pins are tri-stated when a reset condition becomes active, even if the clock is not running. 1 2 3 4 5 6 7 14 13 12 11 10 9 8 vcc (pcint8/xtal1/clki) pb0 (pcint9/xtal2) pb1 (pcint11/reset/dw) pb3 (pcint10/int0/oc0a/ckout) pb2 (pcint7/icp/oc0b/adc7) pa7 (pcint6/oc1a/sda/mosi/di/adc6) pa6 gnd pa0 (adc0/aref/pcint0) pa1 (adc1/ain0/pcint1) pa2 (adc2/ain1/pcint2) pa3 (adc3/t0/pcint3) pa4 (adc4/usck/scl/t1/pcint4) pa5 (adc5/do/miso/oc1b/pcint5) pdip/ s oic 1 2 3 4 5 qfn/mlf 15 14 13 12 11 20 19 18 17 16 6 7 8 9 10 note bottom pad should be soldered to ground. dnc: do not connect dnc dnc gnd vcc dnc pa7 (pcint7/icp/oc0b/adc7) pb2 (pcint10/int0/oc0a/ckout) pb3 (pcint11/reset/dw) pb1 (pcint9/xtal2) pb0 (pcint8/xtal1/clki) pa 5 dnc dnc dnc pa 6 pin 16: pa6 (pcint6/oc1a/sda/mosi/di/adc6) pin 20: pa5 (adc5/do/miso/oc1b/pcint5) (adc4/usck/scl/t1/pcint4) pa4 (adc3/t0/pcint3) pa3 (adc2/ain1/pcint2) pa2 (adc1/ain0/pcint1) pa1 (adc0/aref/pcint0) pa0
3 8006k?avr?10/10 attiny24/44/84 port b also serves the functions of various s pecial features of the attiny24/44/84 as listed in section 10.2 ?alternate port functions? on page 58 . 1.1.4 reset reset input. a low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running and prov ided the reset pin has not been disabled. the min- imum pulse length is given in table 20-4 on page 177 . shorter pulses are not guaranteed to generate a reset. the reset pin can also be used as a (weak) i/o pin. 1.1.5 port a (pa7:pa0) port a is a 8-bit bi-directional i/o port with inte rnal pull-up resistors (selected for each bit). the port a output buffers have symmetrical drive characteristics with both high sink and source capability. as inputs, port a pi ns that are externally pulled low will source current if the pull-up resistors are activated. the port a pins are tri-stated when a reset condition becomes active, even if the clock is not running. port a has alternate functions as analog inputs for the adc, analog comparator, timer/counter, spi and pin change interrupt as described in ?alternate port functions? on page 58 .
4 8006k?avr?10/10 attiny24/44/84 2. overview attiny24/44/84 is a low-power cmos 8-bit microcontroller based on the avr enhanced risc architecture. by executing powerful instructions in a single clock cycle, the attiny24/44/84 achieves throughputs approaching 1 mips per mhz allowing the system designer to optimize power consumption versus processing speed. figure 2-1. block diagram the avr core combines a rich instruction set with 32 general purpose working registers. all 32 registers are directly connected to the arithmetic logic unit (alu), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. the resulting architecture is more code efficient while achiev ing throughputs up to ten times faster than con- ventional cisc microcontrollers. watchdog timer mcu control register timer/ counter0 data dir. reg.port a data register port a programming logic timing and control mcu status register port a drivers pa7-pa0 vcc gnd + - analog comparator 8-bit databus adc isp interface interrupt unit eeprom internal oscillator oscillators calibrated oscillator internal data dir. reg.port b data register port b port b drivers pb3-pb0 program counter stack pointer program flash sram general purpose registers instruction register instruction decoder status register z y x alu control lines timer/ counter1
5 8006k?avr?10/10 attiny24/44/84 the attiny24/44/84 provides the following featur es: 2/4/8k byte of in-system programmable flash, 128/256/512 bytes eeprom, 128/256/512 bytes sram, 12 general purpose i/o lines, 32 general purpose working registers, an 8-bit timer/counter with two pwm channels, a 16-bit timer/counter with two pwm channels, internal and external interrupts, a 8-channel 10-bit adc, programmable gain stage (1x, 20x) for 12 differential adc channel pairs, a programmable watchdog timer with internal oscill ator, internal calibrated oscillato r, and four software select- able power saving modes. idle mode stops the cpu while allowing the sram, timer/counter, adc, analog comparator, and interrupt system to continue functioning. adc noise reduction mode minimizes switching noise during adc conv ersions by stopping the cpu and all i/o mod- ules except the adc. in power-down mode registers keep their contents and all chip functions are disbaled until the next interrupt or hardware reset. in standby mode, the crystal/resonator oscillator is running while the rest of the device is sleeping, allo wing very fast start-up combined with low power consumption. the device is manufactured using atmel?s high density non-volatile memory technology. the on- chip isp flash allows the program memory to be re-programmed in-system through an spi serial interface, by a conventional non-volatile memory programmer or by an on-chip boot code running on the avr core. the attiny24/44/84 avr is supported with a full suite of program and system development tools including: c compilers, macro as semblers, program debugger/simulators and evaluation kits.
6 8006k?avr?10/10 attiny24/44/84 3. about 3.1 resources a comprehensive set of drivers, application notes, data sheets and descriptions on development tools are available for download at http://www.atmel.com/avr. 3.2 code examples this documentation contains simple code examples that briefly show how to use various parts of the device. these code examples assume that the part specific header file is included before compilation. be aware that not all c compiler vendors include bit definitions in the header files and interrupt handling in c is compiler dependent. please confirm with the c compiler documen- tation for more details. for i/o registers located in the extended i/o map, ?in?, ?out?, ?sbis?, ?sbic?, ?cbi?, and ?sbi? instructions must be replaced with instructions that allow access to extended i/o. typically, this means ?lds? and ?sts? combined with ?sbrs?, ?s brc?, ?sbr?, and ?cbr?. note that not all avr devices include an extended i/o map. 3.3 data retention reliability qualification results show that the pr ojected data retention failure rate is much less than 1 ppm over 20 years at 85c or 100 years at 25c. 3.4 disclaimer typical values contained in this datasheet ar e based on simulations and characterization of other avr microcontrollers manufactured on the same process technology.
7 8006k?avr?10/10 attiny24/44/84 4. cpu core this section discusses the avr core architecture in general. the main function of the cpu core is to ensure correct program execution. the cpu must therefore be able to access memories, perform calculations, control peripherals, and handle interrupts. 4.1 architectural overview figure 4-1. block diagram of the avr architecture in order to maximize performance and parallelism, the avr uses a harvard architecture ? with separate memories and buses for program and data. instructions in the program memory are executed with a single level pipelining. while one instruction is being executed, the next instruc- tion is pre-fetched from the program memory. this concept enables instructions to be executed in every clock cycle. the program memory is in-system reprogrammable flash memory. flash program memory instruction register instruction decoder program counter control lines 32 x 8 general purpose registrers alu status and control i/o lines eeprom data bus 8-bit data sram direct addressing indirect addressing interrupt unit watchdog timer analog comparator timer/counter 0 timer/counter 1 universal serial interface
8 8006k?avr?10/10 attiny24/44/84 the fast-access register file contains 32 x 8-bit general purpose working registers with a single clock cycle access time. this allows single-cycle ar ithmetic logic unit (alu ) operation. in a typ- ical alu operation, two operands are output from the register file, the operation is executed, and the result is stored back in the register file ? in one clock cycle. six of the 32 registers can be used as three 16-b it indirect address register pointers for data space addressing ? enabling efficient address calculations. one of the these address pointers can also be used as an address pointer for look up tables in flash program memory. these added function registers are the 16-bit x-, y-, and z-register, described later in this section. the alu supports arithmetic and logic operations between registers or between a constant and a register. single register operations can also be executed in the alu. after an arithmetic opera- tion, the status register is updated to reflect information about the result of the operation. program flow is provided by conditional and unconditional jump and call instructions, capable of directly addressing the whole address space. most avr instructions have a single 16-bit word format but 32-bit wide instructions also exist. th e actual instruction set varies, as some devices only implement a part of the instruction set. during interrupts and subroutine calls, the return address program counter (pc) is stored on the stack. the stack is effectively allocated in the general data sram, and consequently the stack size is only limited by the to tal sram size and the usage of the sram. all user programs must initialize the sp in the reset routine (before subroutines or interrupts are executed). the stack pointer (sp) is read/write accessible in the i/o space. the data sram can easily be accessed through the five different addressing modes supported in the avr architecture. the memory spaces in the avr architecture are all linear and regular memory maps. a flexible interrupt module has its control r egisters in the i/o space with an additional global interrupt enable bit in the status register. all interrupts have a separate interrupt vector in the interrupt vector table. the interrupts have priority in accordance with their interrupt vector posi- tion. the lower the interrupt vector address, the higher the priority. the i/o memory space contains 64 addresses for cpu peripheral functi ons as control regis- ters, spi, and other i/o functions. the i/o memory can be accessed directly, or as the data space locations following those of the register file, 0x20 - 0x5f. 4.2 alu ? arithm etic logic unit the high-performance avr alu operates in dire ct connection with all the 32 general purpose working registers. within a single clock cycle, arithmetic operations between general purpose registers or between a register and an immediate are executed. the alu operations are divided into three main categories ? arithmetic, logical, and bit-functions. some implementations of the architecture also provide a powerful multiplier supporting both signed/unsigned multiplication and fractional format. see the ?instruction set? section for a detailed description. 4.3 status register the status register contains information about the result of the most recently executed arithme- tic instruction. this information can be used for altering program flow in order to perform conditional operations. note that the status register is updated after all alu operations, as specified in the instruction set reference. this will in many cases remove the need for using the dedicated compare instructions, resulting in faster and more compact code.
9 8006k?avr?10/10 attiny24/44/84 the status register is neither automaticall y stored when entering an interrupt routine, nor restored when returning from an interrupt. this must be handled by software. 4.3.1 sreg ? avr status register ? bit 7 ? i: global interrupt enable the global interrupt enable bit must be set for th e interrupts to be enabled. the individual inter- rupt enable control is then performed in separate control registers. if the global interrupt enable register is cleared, none of the interrupts are enabled independent of the individual interrupt enable settings. the i-bit is cleared by hardware after an interrupt has occurred, and is set by the reti instruction to enable subsequent interrupts. the i-bit can also be set and cleared by the application with the sei and cli instructions, as described in the instruction set reference. ? bit 6 ? t: bit copy storage the bit copy instructions bld (bit load) and bst (b it store) use the t-bit as source or desti- nation for the operated bit. a bit from a register in the register file can be copied into t by the bst instruction, and a bit in t can be copied into a bit in a register in the register file by the bld instruction. ? bit 5 ? h: half carry flag the half carry flag h indicates a half carry in some arithmetic operation s. half carry is useful in bcd arithmetic. see the ?instruction set description? for detailed information. ? bit 4 ? s: sign bit, s = n v the s-bit is always an exclusive or between the negative flag n and the two?s complement overflow flag v. see the ?instruction set description? for detailed information. ? bit 3 ? v: two?s complement overflow flag the two?s complement overflow flag v suppor ts two?s complement arithmetics. see the ?instruction set description? for detailed information. ? bit 2 ? n: negative flag the negative flag n indicates a negative result in an arithmetic or logic operation. see the ?instruction set description? for detailed information. ? bit 1 ? z: zero flag the zero flag z indicates a zero result in an arithmetic or logic operation. see the ?instruction set description? for detailed information. ? bit 0 ? c: carry flag the carry flag c indicates a carry in an arithmetic or logic operation. see the ?instruction set description? for de tailed information. bit 76543210 0x3f (0x5f) i t h s v n z c sreg read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
10 8006k?avr?10/10 attiny24/44/84 4.4 general purpose register file the register file is optimized for the avr enhanc ed risc instruction set. in order to achieve the required performance and flex ibility, the following in put/output schemes ar e supported by the register file: ? one 8-bit output operand and one 8-bit result input ? two 8-bit output operands and one 8-bit result input ? two 8-bit output operands and one 16-bit result input ? one 16-bit output operand and one 16-bit result input figure 4-2 below shows the structure of the 32 general purpose working registers in the cpu. figure 4-2. avr cpu general purpose working registers most of the instructions operating on the register file have direct access to all registers, and most of them are single cycle instructions. as shown in figure 4-2 , each register is also assigned a data memory address, mapping them directly into the first 32 locations of the user data space. although not being physically imple- mented as sram locations, this memory organization provides great flexibility in access of the registers, as the x-, y- and z-pointer registers can be set to index any register in the file. 4.4.1 the x-register, y-register, and z-register the registers r26..r31 have some added functions to their general purpose usage. these reg- isters are 16-bit address pointers for indirect addressing of the data space. the three indirect address registers x, y, and z are defined as described in figure 4-3 below. 7 0 addr. r0 0x00 r1 0x01 r2 0x02 ? r13 0x0d general r14 0x0e purpose r15 0x0f working r16 0x10 registers r17 0x11 ? r26 0x1a x-register low byte r27 0x1b x-register high byte r28 0x1c y-register low byte r29 0x1d y-register high byte r30 0x1e z-register low byte r31 0x1f z-register high byte
11 8006k?avr?10/10 attiny24/44/84 figure 4-3. the x-, y-, and z-registers in the different addressing modes these address registers have functions as fixed displacement, automatic increment, and automatic decrement (see the instruction set reference for details). 4.5 stack pointer the stack is mainly used for storing temporary data, for storing local variables and for storing return addresses after interrupts and subroutine calls. the stack pointer register always points to the top of the stack. note that the stack is implemented as growing from higher memory loca- tions to lower memory locations. this implies that a stack push command decreases the stack pointer. the stack pointer points to the data sram stack area where the subroutine and interrupt stacks are located. this stack space in the data sram must be defined by the program before any subroutine calls are executed or interrupts are enabled. the stack pointer must be set to point above 0x60. the stack pointer is decrement ed by one when data is pushed onto the stack with the push instruction, and it is decremented by two when the return address is pushed onto the stack with subroutine call or interrupt. the stack pointer is incremented by one when data is popped from the stack with the pop instruction, and it is incremented by two when data is popped from the stack with return from subroutine ret or return from interrupt reti. the avr stack pointer is implemented as two 8- bit registers in the i/o space. the number of bits actually used is implementation dependent. note that the data space in some implementa- tions of the avr architecture is so small that only spl is needed. in this case, the sph register will not be present. 4.5.1 sph and spl ? stack pointer register 15 xh xl 0 x-register 707 0 r27 (0x1b) r26 (0x1a) 15 yh yl 0 y-register 707 0 r29 (0x1d) r28 (0x1c) 15 zh zl 0 z-register 7070 r31 (0x1f) r30 (0x1e) bit 151413121110 9 8 0x3e (0x5e) sp15 sp14 sp13 sp12 sp11 sp10 sp9 sp8 sph 0x3d (0x5d) sp7 sp6 sp5 sp4 sp3 sp2 sp1 sp0 spl 76543210 read/write r/w r/w r/w r/w r/w r/w r/w r/w read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value ramend ramend ramend ramend ramend ramend ramend ramend initial value ramend ramend ramend ramend ramend ramend ramend ramend
12 8006k?avr?10/10 attiny24/44/84 4.6 instruction execution timing this section describes the general access timi ng concepts for instruction execution. the avr cpu is driven by the cpu clock clk cpu , directly generated from the selected clock source for the chip. no internal clo ck division is used. figure 4-4 shows the parallel instruction fetches and instruction executions enabled by the har- vard architecture and the fast access register file concept. this is the basic pipelining concept to obtain up to 1 mips per mhz with the corr esponding unique results for functions per cost, functions per clocks, and functions per power-unit. figure 4-4. the parallel instruction fetches and instruction executions figure 4-5 shows the internal timing concept for the register file. in a single clock cycle an alu operation using two register operands is executed, and the result is stored back to the destina- tion register. figure 4-5. single cycle alu operation 4.7 reset and inte rrupt handling the avr provides several different interrupt sources. these interrupts and the separate reset vector each have a separate program vector in the program memory space. all interrupts are assigned individual enable bits which must be written logic one together with the global interrupt enable bit in the status register in order to enable the interrupt. the lowest addresses in the program memory space are by default defined as the reset and interrupt vectors. the complete list of vectors is shown in ?interrupts? on page 48 . the list also determines the priority levels of the different interrupts. the lower the address the higher is the clk 1 s t in s tr u ction fetch 1 s t in s tr u ction exec u te 2nd in s tr u ction fetch 2nd in s tr u ction exec u te 3 rd in s tr u ction fetch 3 rd in s tr u ction exec u te 4th in s tr u ction fetch t1 t2 t 3 t4 cpu to t a l exec u tion time regi s ter oper a nd s fetch alu oper a tion exec u te re su lt write b a ck t1 t2 t 3 t4 clk cpu
13 8006k?avr?10/10 attiny24/44/84 priority level. reset has the highest priority, and next is int0 ? the external interrupt request 0. when an interrupt occurs, the global interrupt enable i-bit is cleared and all interrupts are dis- abled. the user software can write logic one to the i-bit to enable nested interrupts. all enabled interrupts can then interrupt the current interrupt routine. the i-bit is automatically set when a return from interrupt instruction ? reti ? is executed. there are basically two types of interrupts. the fi rst type is triggered by an event that sets the interrupt flag. for these interrupts, the program counter is vectored to the actual interrupt vec- tor in order to execute the interrupt handling routine, and hardware clears the corresponding interrupt flag. interrupt flags can also be cleared by writing a logic one to the flag bit position(s) to be cleared. if an interrupt condition occurs while the corresponding interrupt enable bit is cleared, the interrupt fl ag will be set and remember ed until the interrupt is enabled, or the flag is cleared by software. similarly, if one or more interrupt conditions occur while the global interrupt enable bit is clea red, the corres ponding interrupt fl ag(s) will be set and remembered until the global interrupt enable bit is set, and will then be exec uted by order of priority. the second type of interrupts will trigger as long as the interrupt condition is present. these interrupts do not necessarily have interrupt flags. if the interrupt condition disappears before the interrupt is enabled, the in terrupt will not be triggered. when the avr exits from an inte rrupt, it will always retu rn to the main pr ogram and execute one more instruction before any pending interrupt is served. note that the status register is not automatica lly stored when entering an interrupt routine, nor restored when returning from an interrupt routine. this must be handled by software. when using the cli instruction to disable interrupts, the interrup ts will be immediately disabled. no interrupt will be executed af ter the cli instruction, even if it occurs simultaneously with the cli instruction. the following example shows how this can be used to avoid interrupts during the timed eeprom write sequence. note: see ?code examples? on page 6 . assembly code example in r16, sreg ; store sreg value cli ; disable interrupts during timed sequence sbi eecr, eempe ; start eeprom write sbi eecr, eepe out sreg, r16 ; restore sreg value (i-bit) c code example char csreg; csreg = sreg; /* store sreg value */ /* disable interrupts during timed sequence */ _cli(); eecr |= (1< 14 8006k?avr?10/10 attiny24/44/84 when using the sei instruction to enable interr upts, the instruction following sei will be exe- cuted before any pending interrupts, as shown in the following example. note: see ?code examples? on page 6 . 4.7.1 interrupt response time the interrupt execution response for all the enabl ed avr interrupts is four clock cycles mini- mum. after four clock cycles the program vector address for the actual interrupt handling routine is executed. during this four clock cycle period, the program counter is pushed onto the stack. the vector is normally a jump to the interrupt routine, and this jump takes three clock cycles. if an interrupt occurs during execution of a multi- cycle instruction, this in struction is completed before the interrupt is served. if an interrupt occurs when the mcu is in sleep mode, the interrupt execution response time is increased by four clock cycles. this increase comes in addition to the start-up time from the selected sleep mode. a return from an interrupt handling routine take s four clock cycles. during these four clock cycles, the program counter (two bytes) is popped back from the stack, the stack pointer is incremented by two, and the i-bit in sreg is set. assembly code example sei ; set global interrupt enable sleep ; enter sleep, waiting for interrupt ; note: will enter sleep before any pending ; interrupt(s) c code example _sei(); /* set global interrupt enable */ _sleep(); /* enter sleep, waiting for interrupt */ /* note: will enter sleep before any pending interrupt(s) */
15 8006k?avr?10/10 attiny24/44/84 5. memories this section describes the different memories in the attiny24/44/84. the avr architecture has two main memory spaces, the data memory and the program memory space. in addition, the attiny24/44/84 feat ures an eeprom memory for data storag e. all three memory spaces are lin- ear and regular. 5.1 in-system re-programmable flash program memory the attiny24/44/84 contains 2/4/8k byte on-chip in-system reprogrammable flash memory for program storage. since all avr instructions ar e 16 or 32 bits wide, the flash is organized as 1024/2048/4096 x 16. the flash memory has an endurance of at least 10,000 write/erase cycles. the attiny24/44/84 program counter (pc) is 10/11/12 bits wide, thus addressing the 1024/2048/4096 program memory locations. ?memory programming? on page 159 contains a detailed description on flash data serial downloading using the spi pins. constant tables can be allocated within the entire program memory address space (see instruc- tions lpm ? load program memory and spm ? store program memory). timing diagrams for instruction fetch and execution are presented in ?instruction execution tim- ing? on page 12 . figure 5-1. program memory map 5.2 sram data memory figure 5-2 on page 16 shows how the attiny24/44/84 sram memory is organized. the lower data memory locations address both the register file, the i/o memory and the inter- nal data sram. the first 32 locations address the register file, the next 64 locations the standard i/o memory, and the last 128/256/512 locations address the internal data sram. the five different addressing modes for the data memory cover: direct, indirect with displace- ment, indirect, indirect with pre-decrement, and indirect with post-increment. in the register file, registers r26 to r31 feature the indirect addressing pointer registers. the direct addressing reaches the entire data space. the indirect with displacement mode reaches 63 address locations from the base address given by the y- or z-register. 0x0000 0x03ff/0x07ff/0xfff program memory
16 8006k?avr?10/10 attiny24/44/84 when using register indirect addressing modes with automatic pre-decrement and post-incre- ment, the address registers x, y, and z are decremented or incremented. the 32 general purpose working registers, 64 i/o registers, and the 128/256/512 bytes of inter- nal data sram in the attiny24/44/84 are all ac cessible through all these addressing modes. the register file is described in ?general purpose register file? on page 10 . figure 5-2. data memory map 5.2.1 data memory access times this section describes the general access timi ng concepts for internal memory access. the internal data sram access is performed in two clk cpu cycles as illustrated in figure 5-3 . figure 5-3. on-chip data sram access cycles 5.3 eeprom data memory the attiny24/44/84 contains 128/256/512 bytes of data eeprom memory. it is organized as a separate data space, in which single bytes can be read and written. the eeprom has an endurance of at least 100,000 write/erase cycles. the access between the eeprom and the cpu is described in the following, specif ying the eeprom address registers, the eeprom data register, and the eeprom control register. for a detailed description of serial data downloading to the eeprom, see ?serial programming? on page 163 . 32 registers 64 i/o registers internal sram (128/256/512 x 8) 0x0000 - 0x001f 0x0020 - 0x005f 0x0df/0x015f/0x025f 0x0060 data memory clk wr rd d a t a d a t a addre ss addre ss v a lid t1 t2 t 3 comp u te addre ss re a d write cpu memory acce ss in s tr u ction next in s tr u ction
17 8006k?avr?10/10 attiny24/44/84 5.3.1 eeprom read/write access the eeprom access registers are accessible in the i/o space. the write access times for the eeprom are given in table 5-1 on page 22 . a self-timing func- tion, however, lets the user software detect when the next byte can be written. if the user code contains instructions that write the eeprom, so me precautions must be taken. in heavily fil- tered power supplies, v cc is likely to rise or fall slo wly on power-up/down. this causes the device for some period of time to run at a voltage lower than specified as minimum for the clock frequency used. see ?preventing eeprom corruption? on page 19 for details on how to avoid problems in these situations. in order to prevent unintentional eeprom writes, a specific write procedure must be followed. see ?atomic byte programming? on page 17 and ?split byte programming? on page 17 for details on this. when the eeprom is read, the cpu is halted for fo ur clock cycles before the next in struction is executed. when the eeprom is written, the cp u is halted for two clock cycles before the next instruction is executed. 5.3.2 atomic byte programming using atomic byte programming is the simplest mode. when writing a by te to the eeprom, the user must write the addr ess into register eear and data into register eedr. if the eepmn bits are zero, writing eepe (within four cycles after ee mpe is written) will trigger the erase/write operation. both the erase and write cycle are done in one operation and the total programming time is given in table 5-1 on page 22 . the eepe bit remains set until the erase and write opera- tions are completed. while t he device is busy with programming , it is not possible to do any other eeprom operations. 5.3.3 split byte programming it is possible to split the erase and write cycle in two different operations. this may be useful if the system requires short access time for some limited period of ti me (typically if the power sup- ply voltage falls). in order to take advantage of this method, it is required that the locations to be written have been erased before the write operation. but since the erase and write operations are split, it is possible to do the erase operations when the system allows doing time-critical operations (typically after power-up). 5.3.4 erase to erase a byte, the address must be written to eear. if the eepmn bits are 0b01, writing the eepe (within four cycles after eempe is written) will trigger the erase operation only (program- ming time is given in table 5-1 on page 22 ). the eepe bit remains se t until the erase operation completes. while the device is busy programming, it is not possible to do any other eeprom operations. 5.3.5 write to write a location, the user must write the address into eear and the data into eedr. if the eepmn bits are 0b10, writing the eepe (within f our cycles after eempe is written) will trigger the write operation only (programming time is given in table 5-1 on page 22 ). the eepe bit remains set until the write operation completes. if the location to be written has not been erased before write, the data that is stored must be considered as lost. while the device is busy with programming, it is not possible to do any ot her eeprom operations.
18 8006k?avr?10/10 attiny24/44/84 the calibrated oscillator is used to time the eeprom accesses. make sure the oscillator fre- quency is within the requirements described in ?osccal ? oscillator ca libration register? on page 30 . 5.3.6 program examples the following code examples show one assembly and one c function for erase, write, or atomic write of the eeprom. the examples assume that interrupts are controlled (e.g., by disabling interrupts globally) so that no interrupts will occur during ex ecution of th ese functions. note: see ?code examples? on page 6 . assembly code example eeprom_write: ; wait for completion of previous write sbic eecr, eepe rjmp eeprom_write ; set programming mode ldi r16, (0< 19 8006k?avr?10/10 attiny24/44/84 the next code examples show assembly and c functions for reading the eeprom. the exam- ples assume that interrupts are controlled so that no interrupts will occur during execution of these functions. note: see ?code examples? on page 6 . 5.3.7 preventing eeprom corruption during periods of low v cc , the eeprom data can be corrupted because the supp ly voltage is too low for the cpu and the eeprom to operate properly. these issues are the same as for board level systems using eepr om, and the same design so lutions should be applied. an eeprom data corruption can be caused by two situations when the voltage is too low. first, a regular write sequence to the eeprom requires a minimum voltage to operate correctly. sec- ondly, the cpu itself can execute instructions incorrectly, if the supp ly voltage is too low. eeprom data corruption can ea sily be avoided by followin g this design recommendation: keep the avr reset active (low) during periods of insufficient power su pply voltage. this can be done by enabling the internal brown-out detector (bod). if the detection level of the internal bod does not match the needed detection level, an external low v cc reset protection circuit can assembly code example eeprom_read: ; wait for completion of previous write sbic eecr, eepe rjmp eeprom_read ; set up address (r18:r17) in address registers out eearh, r18 out eearl, r17 ; start eeprom read by writing eere sbi eecr, eere ; read data from data register in r16, eedr ret c code example unsigned char eeprom_read( unsigned int ucaddress) { /* wait for completion of previous write */ while(eecr & (1< 20 8006k?avr?10/10 attiny24/44/84 be used. if a reset occurs while a write operation is in progress , the write operation will be com- pleted provided that the power supply voltage is sufficient. 5.4 i/o memory the i/o space definition of the attiny24/44/84 is shown in ?register summary? on page 213 . all attiny24/44/84 i/os and peripherals are plac ed in the i/o space. all i/o locations may be accessed by the ld/lds/ldd and st/sts/std instructions, transferring data between the 32 general purpose working registers and the i/o space. i/o registers within the address range 0x00 - 0x1f are directly bit-acce ssible using the sbi and cbi instructions. in these registers, the value of single bits can be checked by using the sbis and sbic instructions. see the instruction set section for more details. when using the i/o specific commands in and out, the i/o addresses 0x00 - 0x3f must be used. when addressing i/o registers as data space using ld and st instructions, 0x20 must be added to these addresses. for compatibility with future devices, reserved bits should be written to zero if accessed. reserved i/o memory addresses should never be written. some of the status flags are cleared by writing a logical one to them. note that cbi and sbi instructions will only oper ate on the specified bit, and can th erefore be used on registers contain- ing such status flags. the cbi and sbi instructions work with registers 0x00 to 0x1f only. the i/o and peripherals control registers are explained in later sections. 5.4.1 general purpose i/o registers the attiny24/44/84 contains three general purpos e i/o registers. these registers can be used for storing any information, and they are particular ly useful for storing global variables and status flags. general purpose i/o registers within the address range 0x00 - 0x1f are directly bit- accessible using the sbi, cbi, sbis, and sbic instructions. 5.5 register description 5.5.1 eearh ? eeprom address register ? bits 7:1 ? res: reserved bits these bits are reserved in the attiny 24/44/84 and will always read as zero. ? bit 0 ? eear8: eeprom address this is the most significant eeprom address bit of attiny84. in device s with less eeprom, i.e. attiny24/attiny44, this bit is reserved and will always read ze ro. the initial value of the eeprom address register (eear) is undefined an d a proper value must therefore be written before the eeprom is accessed. bit 76543210 0x1f (0x3f) ???????eear8eearh read/write rrrrrrrr/w initial value 0 0 0 0 0 0 0 x/0
21 8006k?avr?10/10 attiny24/44/84 5.5.2 eearl ? eeprom address register ? bit 7 ? eear7: eeprom address this is the most significant eeprom address bit of attiny44. in device s with less eeprom, i.e. attiny24, this bit is reserved and will always read zero. the initial value of the eeprom address register (eear) is undefined and a proper value must therefore be written before the eeprom is accessed. ? bits 6:0 ? eear6:0: eeprom address these are the (low) bits of the eeprom a ddress register. the eeprom data bytes are addressed linearly in th e range 0...128/256/512. the initial value of eear is undefined and a proper value must be therefore be written before the eeprom may be accessed. 5.5.3 eedr ? eeprom data register ? bits 7:0 ? eedr7:0: eeprom data for the eeprom write operation the eedr register contains the data to be written to the eeprom in the address given by the eear regi ster. for the eeprom read operation, the eedr contains the data read out from the eeprom at the add ress given by eear. 5.5.4 eecr ? eeprom control register ? bit 7 ? res: reserved bit this bit is reserved for future use and will always read as 0 in attiny24/44/84. for compatibility with future avr devices, always write this bit to zero. after reading, mask out this bit. ? bit 6 ? res: reserved bit this bit is reserved in the attiny 24/44/84 and will always read as zero. ? bits 5:4 ? eepm1, eepm0: eepr om programming mode bits the eeprom programming mode bits setting defines which programming action that will be triggered when writing eepe. it is possible to program data in one atomic operation (erase the bit 76543210 0x1e (0x3e) eear7 eear6 eear5 eear4 eear3 eear2 eear1 eear0 eearl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value x x x x x x x x bit 76543210 0x1d (0x3d) eedr7 eedr6 eedr5 eedr4 eedr3 eedr2 eedr1 eedr0 eedr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x1c (0x3c) ? ? eepm1 eepm0 eerie eempe eepe eere eecr read/write r r r/w r/w r/w r/w r/w r/w initial value 0 0 x x 0 0 x 0
22 8006k?avr?10/10 attiny24/44/84 old value and program the new value) or to split the erase and write operations in two different operations. the programming times for the different modes are shown in table 5-1 . when eepe is set any write to eepmn will be ignored. during reset, the eepmn bits will be reset to 0b00 unless the eeprom is busy programming. ? bit 3 ? eerie: eeprom ready interrupt enable writing eerie to one enab les the eeprom ready interrupt if th e i-bit in sreg is set. writing eerie to zero disables the interrupt. the eep rom ready interrupt generates a constant inter- rupt when non-volatile memory is ready for programming. ? bit 2 ? eempe: eeprom master program enable the eempe bit determines whether writing eepe to o ne will have effect or not. when eempe is set, setting eepe within four cl ock cycles will program the eeprom at the selected address. if eempe is zero, setting eepe will have no effect. when eempe has been written to one by software, hardware clears the bit to zero after four clock cycles. ? bit 1 ? eepe: eeprom program enable the eeprom program enable signal eepe is th e programming enable signal to the eeprom. when eepe is written, the eeprom will be pr ogrammed according to the eepmn bits setting. the eempe bit must be written to one before a logical one is written to eepe, otherwise no eeprom write takes place. when the write a ccess time has elapsed, the eepe bit is cleared by hardware. when eepe has been set, the cpu is halted for two cycles before the next instruction is executed. ? bit 0 ? eere: eeprom read enable the eeprom read enable signal ? eere ? is t he read strobe to the eeprom. when the cor- rect address is set up in the eear register, the eere bit must be written to one to trigger the eeprom read. the eeprom read access takes one instruction, and th e requested data is available immediately. when t he eeprom is read, the cpu is ha lted for four cycles before the next instruction is executed. th e user should poll the eepe bit be fore starting the read opera- tion. if a write operation is in progress, it is neither possible to read the eeprom, nor to change the eear register. table 5-1. eeprom programming mode bi ts and programming times eepm1 eepm0 programming time operation 0 0 3.4 ms erase and write in one operation (atomic operation) 0 1 1.8 ms erase only 1 0 1.8 ms write only 1 1 ? reserved for future use
23 8006k?avr?10/10 attiny24/44/84 5.5.5 gpior2 ? general purpose i/o register 2 5.5.6 gpior1 ? general purpose i/o register 1 5.5.7 gpior0 ? general purpose i/o register 0 bit 76543210 0x15 (0x35) msb lsb gpior2 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x14 (0x34) msb lsb gpior1 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x13 (0x33) msb lsb gpior0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
24 8006k?avr?10/10 attiny24/44/84 6. clock system figure 6-1 presents the principal clock systems in the avr and their distribution. all of the clocks need not be active at a given time. in order to reduce power consumption, the clocks to modules not being used can be halted by using different sleep modes, as described in ?power manage- ment and sleep modes? on page 33 . figure 6-1. clock distribution 6.1 clock subsystems the clock subsystems are detailed in the sections below. 6.1.1 cpu clock ? clk cpu the cpu clock is routed to parts of the system concerned with operation of the avr core. examples of such modules are the general pur pose register file, the status register and the data memory holding the stack pointer. halting the cpu clock inhibits the core from performing general operations and calculations. general i/o modules cpu core ram clk i/o avr clock control unit clk cpu flash and eeprom clk flash source clock watchdog timer watchdog oscillator reset logic clock multiplexer watchdog clock calibrated rc oscillator calibrated rc oscillator external clock adc clk adc crystal oscillator low-frequency crystal oscillator system clock prescaler
25 8006k?avr?10/10 attiny24/44/84 6.1.2 i/o clock ? clk i/o the i/o clock is used by the majority of the i/o modules, like timer/counter. the i/o clock is also used by the external interrupt module, but note that some external interrupts are detected by asynchronous logic, allowing such interrupts to be detected even if the i/o clock is halted. 6.1.3 flash clock ? clk flash the flash clock controls operation of the flash in terface. the flash clock is usually active simul- taneously with the cpu clock. 6.1.4 adc clock ? clk adc the adc is provided with a dedicated clock domain. this allows halting the cpu and i/o clocks in order to reduce noise generated by digital circuitry. this gives more accurate adc conversion results. 6.2 clock sources the device has the following clock source options, selectable by flash fuse bits as shown below. the clock from the selected source is input to the avr clock generator, and routed to the appropriate modules. note: 1. for all fuses ?1? means unprogrammed and ?0? means programmed. the various choices for each clocking option is given in the following sections. when the cpu wakes up from power-down the selected clock source is used to time the start-up, ensuring sta- ble oscillator operation before instruction execution starts. when the cpu starts from reset, there is an additional delay allowing the power to reach a stable level before commencing nor- mal operation. the watchdog osc illator is used for timi ng this real-time part of the start-up time. the number of wdt oscillator cycles us ed for each time-out is shown in table 6-2 . table 6-1. device clocking options select device clocking option cksel3:0 (1) external clock (see page 26 ) 0000 reserved 0001 calibrated internal 8 mhz oscillator (see page 26 ) 0010 reserved 0011 internal 128 khz oscillator (see page 27 ) 0100 reserved 0101 low-frequency crystal oscillator (see page 28 ) 0110 reserved 0111 crystal oscillator / ceramic resonator (see page 28 ) 1000-1111 table 6-2. number of watchdog oscillator cycles typ time-out number of cycles 4 ms 512 64 ms 8k (8,192)
26 8006k?avr?10/10 attiny24/44/84 6.2.1 external clock to drive the device from an external clock source, clki should be driven as shown in figure 6-2 on page 26 . to run the device on an external cloc k, the cksel fuses mu st be programmed to ?0000?. figure 6-2. external clock drive configuration when this clock source is sele cted, start-up times are determined by the sut fuses as shown in table 6-3 . when applying an external clock, it is required to avoid sudden changes in the applied clock fre- quency to ensure stable operation of the mcu. a variation in frequency of more than 2% from one clock cycle to the next can lead to unpredictable behavior. it is required to en sure that the mcu is kept in reset during such changes in the clock frequency. note that the system clock prescaler can be used to implement run-time changes of the internal clock frequency while still ensuring stable operation. see ?system clock prescaler? on page 30 for details. 6.2.2 calibrated internal 8 mhz oscillator by default, the internal oscillator provides an approximate 8 mhz clock. though voltage and temperature dependent, this clock can be very accurately calibrated by the user. see table 20-2 on page 176 and ?internal oscillator sp eed? on page 205 for more details. the device is shipped with the ckdiv8 fuse programmed. see ?system clock presca ler? on page 30 for more details. this clock may be selected as the system clock by programming the cksel fuses as shown in table 6-4 . if selected, it will operate with no external comp onents. during rese t, hardware loads the pre-programmed calibration value into the osccal register and thereby automatically cal- table 6-3. start-up times for the external clock selection sut1:0 start-up time from power-down additional delay from reset recommended usage 00 6 ck 14ck bod enabled 01 6 ck 14ck + 4 ms fast rising power 10 6 ck 14ck + 64 ms slowly rising power 11 reserved external clock s ignal clki gnd
27 8006k?avr?10/10 attiny24/44/84 ibrates the rc oscillator. the accuracy of this calibration is shown as factory calibration in table 20-2 on page 176 . by changing the osccal register from sw, see ?osccal ? oscillator ca libration register? on page 30 , it is possible to get a higher calibration accuracy than by using the factory calibration. the accuracy of this calibration is shown as user calibration in table 20-2 on page 176 . when this oscillator is used as the chip clock, the watchdog oscillator will still be used for the watchdog timer and for the reset time-out. for more information on the pre-programmed cali- bration value, see the section ?calibration byte? on page 162 . note: 1. the device is shipped with this option selected. when this oscillator is selected, start-up time s are determined by the sut fuses as shown in table 6-5 . note: 1. the device is shipped with this option selected. 2. if the rstdisbl fuse is programmed, this star t-up time will be increased to 14ck + 4 ms to ensure programming mode can be entered. 6.2.3 internal 128 khz oscillator the 128 khz internal oscillator is a low power oscillator providing a clock of 128 khz. the fre- quency depends on supply voltage, temperature and batch variations. this clock may be selected as the system clock by programming the cksel fuses to ?0100?. when this clock source is sele cted, start-up times are determined by the sut fuses as shown in table 6-6 . note: 1. if the rstdisbl fuse is pr ogrammed, this start-up time will be increased to 14ck + 4 ms to ensure programming mode can be entered. table 6-4. internal calibrated rc o scillator operating modes cksel3:0 nominal frequency 0010 (1) 8.0 mhz table 6-5. start-up times for the internal calib rated rc oscillato r clock selection sut1:0 start-up time from power-down additional delay from reset (v cc = 5.0v) recommended usage 00 6 ck 14ck (2) bod enabled 01 6 ck 14ck + 4 ms fast rising power 10 (1) 6 ck 14ck + 64 ms slowly rising power 11 reserved table 6-6. start-up times for the 128 khz internal oscillator sut1:0 start-up time from power-down additional delay from reset recommended usage 00 6 ck 14ck (1) bod enabled 01 6 ck 14ck + 4 ms fast rising power 10 6 ck 14ck + 64 ms slowly rising power 11 reserved
28 8006k?avr?10/10 attiny24/44/84 6.2.4 low-frequency crystal oscillator to use a 32.768 khz watch crystal as the clock source for the device, the low-frequency crystal oscillator must be selected by setting cksel fu ses to ?0110?. the cryst al should be connected as shown in figure 6-3 . to find suitable capacitors please consult the manufacturer?s datasheet. for this oscillator start-up times can be set with the sut fuses, as shown in table 6-7 . notes: 1. these options should be used only if frequency stability at st art-up is not important. the low-frequency crystal oscillator provides an internal load capacitance, see table 6-8 at each tosc pin. 6.2.5 crystal oscillator / ceramic resonator xtal1 and xtal2 are input and output, respectively, of an inverting amplifier which can be con- figured for use as an on-chip oscillator, as shown in figure 6-3 either a quartz crystal or a ceramic resonator may be used. figure 6-3. crystal oscillator connections c1 and c2 should always be equal for both crystals and resonators. the optimal value of the capacitors depends on the crystal or resonator in use, the amount of stray capacitance, and the electromagnetic noise of the environment. some initial guidelines for choosing capacitors for use with crystals are given in table 6-9 below. for ceramic resonators, the capacitor values given by the manufacturer should be used. table 6-7. start-up times for the low-frequency crystal oscillator clock selection sut1:0 start-up time from power down additional delay from reset recommended usage 00 1k ck (1) 4 ms fast rising power or bod enabled 01 1k ck (1) 64 ms slowly rising power 10 32k ck 64 ms stable frequency at start-up 11 reserved table 6-8. capacitance for the low-fr equency crystal oscillator device 32 khz osc. type cap (xtal1/tosc1) cap (xtal2/tosc2) attiny24/44/84 system osc. 16 pf 6 pf xtal2 xtal1 gnd c2 c1
29 8006k?avr?10/10 attiny24/44/84 notes: 1. this option should not be used with crystals, only with ceramic resonators. the oscillator can operate in three different mo des, each optimized for a specific frequency range. the operating mode is selected by fuses cksel3:1 as shown in table 6-9 . the cksel0 fuse together with the sut1:0 fuses select the start-up times as shown in table 6-10 . notes: 1. when the bod has been disabled by software, the wake-up time from sleep mode will be approximately 60s to ensure that the bod is working correctly before the mcu continues executing code. 2. these options should only be used when not operating close to the maximum frequency of the device, and only if frequency stability at start- up is not important for the application. these options are not suitable for crystals. 3. these options are intended for use with cerami c resonators and will ensure frequency stability at start-up. they can also be used with crystal s when not operating close to the maximum fre- quency of the device, and if frequency stability at start-up is not important for the application. table 6-9. crystal oscillator operating modes cksel3:1 frequency range (mhz) reco mmended c1 and c2 value (pf) 100 (1) 0.4 - 0.9 ? 101 0.9 - 3.0 12 - 22 110 3.0 - 8.0 12 - 22 111 8.0 - 12 - 22 table 6-10. start-up times for the crysta l oscillator clock selection cksel0 sut1:0 start-up time from power-down (1) additional delay from reset recommended usage 0 00 258 ck (2) 14ck + 4 ms ceramic resonator, fast rising power 0 01 258 ck (2) 14ck + 64 ms ceramic resonator, slowly rising power 010 1k ck (3) 14ck ceramic resonator, bod enabled 011 1k ck (3) 14ck + 4 ms ceramic resonator, fast rising power 100 1k ck (3) 14ck + 64 ms ceramic resonator, slowly rising power 1 01 16k ck 14ck crystal oscillator, bod enabled 1 10 16k ck 14ck + 4 ms crystal oscillator, fast rising power 1 11 16k ck 14ck + 64 ms crystal oscillator, slowly rising power
30 8006k?avr?10/10 attiny24/44/84 6.2.6 default clock source the device is shipped with cksel = ?0010?, sut = ?10?, and ckdiv8 programmed. the default clock source setting is therefore the internal oscillator running at 8.0 mhz with longest start-up time and an initial system clock prescaling of 8, resulting in 1.0 mhz system clock. this default setting ensures that all users can make their desired clock source setting using an in-system or high-voltage programmer. for low-voltage devices (attiny24v/44v/84v ) it should be noted that unprogramming the ckdiv8 fuse may result in over clocking. at low voltages (below 2.7v) the devices are rated for maximum 4 mhz operation (see section 20.3 on page 175 ), but routing the clock signal from the internal oscillator directly to the syst em clock line will run the device at 8 mhz. 6.3 system clock prescaler the attiny24/44/84 system clock can be divided by setting the ?clkpr ? clock prescale regis- ter? on page 31 . this feature can be used to decrease power consumption when the requirement for processing power is low. this can be used with all clock source options, and it will affect the clock frequency of the cp u and all synchronou s peripherals. clk i/o , clk adc , clk cpu , and clk flash are divided by a factor as shown in table 6-11 on page 32 . 6.3.1 switching time when switching between prescaler settings, the system clock prescaler ensures that no glitches occur in the clock system and that no intermediate frequency is higher than neither the clock frequency corresponding to the previous setting, nor the clock frequency corresponding to the new setting. the ripple counter that implements the prescaler runs at the frequency of the undivided clock, which may be faster than the cpu?s clock frequency. hence, it is not possible to determine the state of the prescaler ? even if it were readable, and the exact time it takes to switch from one clock division to another cannot be exactly predicted. from the time the clkps values ar e written, it takes between t1 + t2 and t1 + 2*t2 before the new clock frequency is active. in this interval, 2 active clock edges are produced. here, t1 is the previous clock period, and t2 is the period corresponding to the new prescaler setting. 6.4 clock output buffer the device can output the system clock on the ckout pin. to enable the output, the ckout fuse has to be programmed. this mode is suitable when the chip clock is used to drive other cir- cuits on the system. note that the clock will not be output duri ng reset and t hat the normal operation of the i/o pin will be overridden when t he fuse is programmed. any clock source, including the internal rc oscillator, can be sele cted when the clock is output on ckout. if the system clock prescaler is used, it is the divided system clock that is output. 6.5 register description 6.5.1 osccal ? oscillato r calibration register ? bits 7:0 ? cal7:0: oscillator calibration value bit 76543210 0x31 (0x51) cal7 cal6 cal5 cal4 cal3 cal2 cal1 cal0 osccal read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value device spec ific calibration value
31 8006k?avr?10/10 attiny24/44/84 the oscillator calibration register is used to trim the calibrated internal rc oscillator to remove process variations from the oscillator frequency. a pre-programmed calibration value is automatically written to this register during chip reset, giving the factory calibrated frequency as specified in table 20-2 on page 176 . the application software can write this register to change the oscillator frequency. the os cillator can be calibrated to frequencies as specified in table 20- 2 on page 176 . calibration outside that range is not guaranteed. note that this o scillator is used to time eeprom and flash write accesses , and these write times will be affected accordingly. if the eeprom or flash are writ ten, do not calibrate to more than 8.8 mhz. other wise, the eeprom or flash write may fail. the cal7 bit determines the range of operation for the oscillator. setting this bit to 0 gives the lowest frequency range, setting this bit to 1 gives the highest frequency range. the two fre- quency ranges are overlapping, in other words a setting of osccal = 0x7f gives a higher frequency than osccal = 0x80. the cal6:0 bits are used to tune the frequency within the selected range. a setting of 0x00 gives the lowest frequency in that range, and a setting of 0x7f gives the highest frequency in the range. see ?calibrated 8 mhz rc oscillator freque ncy vs. osccal value? on page 207 for typ- ical frequencies. to ensure stable operation of the mcu the calibration value should be changed in small. a vari- ation in frequency of more than 2% from one cycle to the next can lead to unpredicatble behavior. changes in osccal should not exceed 0x20 for each calibration. it is required to ensure that the mcu is kept in reset during such changes in the clock frequency. 6.5.2 clkpr ? clock prescale register ? bit 7 ? clkpce: clock prescaler change enable the clkpce bit must be written to logic one to enab le change of the clkps bits. the clkpce bit is only updated when the other bits in clkpr are simultaniosly written to zero. clkpce is cleared by hardware four cycles af ter it is written or when the clkps bits are written. rewriting the clkpce bit within this time-out period does neither extend the time-out period, nor clear the clkpce bit. ? bits 6:4 ? res: reserved bits these bits are reserved in the attiny 24/44/84 and will always read as zero. ? bits 3:0 ? clkps3:0: clock prescaler select bits 3 - 0 these bits define the division factor between the selected clock source and the internal system clock. these bits can be written run-time to vary the clock frequency to suit the application requirements. as the divider divides the master clock input to the mcu, the speed of all synchro- nous peripherals is reduced when a division fact or is used. the division factors are given in table 6-11 on page 32 . to avoid unintentional changes of clock frequency, a special write procedure must be followed to change the clkps bits: bit 76543210 0x26 (0x46) clkpce ? ? ? clkps3 clkps2 clkps1 clkps0 clkpr read/write r/w r r r r/w r/w r/w r/w initial value 0 0 0 0 see bit description
32 8006k?avr?10/10 attiny24/44/84 1. write the clock prescaler change enable (clkpce) bit to one and all other bits in clkpr to zero. 2. within four cycles, write the desired valu e to clkps while writing a zero to clkpce. interrupts must be disabled when changing prescaler setting to make sure the write procedure is not interrupted. the ckdiv8 fuse determines the initial value of the clkps bits. if ckdiv8 is unprogrammed, the clkps bits will be reset to ?0000?. if ckdiv8 is programmed, clkps bits are reset to ?0011?, giving a division factor of eight at star t up. this feature should be used if the selected clock source has a higher frequency than the maximum frequency of the device at the present operating conditions. note that any value can be written to the clkps bits regardless of the ckdiv8 fuse setting. the application software must ensure that a sufficient division factor is chosen if the selcted clock source has a highe r frequency than the maximum frequency of the device at the present operating conditions. the device is shipped with the ckdiv8 fuse programmed. table 6-11. clock prescaler select clkps3 clkps2 clkps1 clkps0 clock division factor 0000 1 0001 2 0010 4 0011 8 0100 16 0101 32 0110 64 0111 128 1000 256 1001 reserved 1010 reserved 1011 reserved 1100 reserved 1101 reserved 1110 reserved 1111 reserved
33 8006k?avr?10/10 attiny24/44/84 7. power management and sleep modes the high performance and industry leading code efficiency makes the avr microcontrollers an ideal choise for low power applications. in addition, sleep modes enable the application to shut down unused modules in the mcu, thereby saving power. the avr provides various sleep modes allowing the user to tailor the power consumption to the application?s requirements. 7.1 sleep modes figure 6-1 on page 24 presents the different clock systems and their distribution in attiny24/44/84. the figure is helpful in selecting an appropriate sleep mode. table 7-1 shows the different sleep modes and their wake up sources. note: 1. for int0, only level interrupt. to enter any of the three sleep modes, the se bit in mcucr must be written to logic one and a sleep instruction must be execut ed. the sm1:0 bits in the mcu cr register select which sleep mode (idle, adc noise reduction, standby or power-down) will be ac tivated by the sleep instruction. see table 7-2 on page 37 for a summary. if an enabled interrupt occurs while the mcu is in a sleep mode, the mcu wakes up. the mcu is then halted for four cycles in addition to the st art-up time, executes the interrupt routine, and resumes execution from the instruction followi ng sleep. the contents of the register file and sram are unaltered when the device wakes up from sleep. if a reset occurs during sleep mode, the mcu wakes up and executes from the reset vector. note that if a level triggered interrupt is used for wake-up the changed level must be held for some time to wake up the mcu (and for the mcu to enter the interrupt service routine). see ?external interrupts? on page 49 for details. 7.1.1 idle mode when the sm1:0 bits are written to 00, the sl eep instruction makes the mcu enter idle mode, stopping the cpu but allowing analog comparator , adc, timer/counter, watchdog, and the interrupt system to continue operating. this sleep mode basically halts clk cpu and clk flash , while allowing the other clocks to run. idle mode enables the mcu to wake up from external triggered interrupts as well as internal ones like the timer overflow. if wake-up from the analog comparator interrupt is not required, table 7-1. active clock domains and wake-up sources in different sleep modes sleep mode active clock domains oscillators wake-up sources clk cpu clk flash clk io clk adc main clock source enabled int0 and pin change spm/eeprom ready interrupt adc interrupt other i/o watchdog interrupt idle xx x xxxxx adc noise reduction x x x (1) xx x power-down x (1) x stand-by x (1) x
34 8006k?avr?10/10 attiny24/44/84 the analog comparator can be powered down by setting the acd bit in ?acsr ? analog com- parator control and status register? on page 130 . this will reduce power consumption in idle mode. if the adc is enabled, a conversion starts automatically when this mode is entered. 7.1.2 adc noise reduction mode when the sm1:0 bits are written to 01, the sleep instruction makes th e mcu enter adc noise reduction mode, stopping the cpu but allowing the adc, the external interrupts, and the watchdog to continue operating (if enabled). this sleep mode halts clk i/o , clk cpu , and clk flash , while allowing the ot her clocks to run. this improves the noise environment for the ad c, enabling higher resolution measurements. if the adc is enabled, a conversion starts automatically when this mode is entered. apart form the adc conversion complete interrupt, only an external reset, a watchdog reset, a brown-out reset, an spm/eeprom ready inte rrupt, an external level interr upt on int0 or a pin change interrupt can wake up the mcu from adc noise reduction mode. 7.1.3 power-down mode when the sm1:0 bits are written to 10, the sleep instruction makes the mcu enter power- down mode. in this mode, the os cillator is stopped, while the ex ternal interrupts, and the watch- dog continue operating (if enabled). only an external reset, a watchdog reset, a brown-out reset, an external level interrupt on int0, or a pin change interrupt can wake up the mcu. this sleep mode halts all generated clocks, allowing operation of asynchronous modules only. 7.1.4 standby mode when the sm1:0 bits are 11 and an external crystal/resonator clock option is selected, the sleep instruction makes the mcu enter standby mode. this mode is identical to power-down with the exception that the oscillator is kept running. fr om standby mode, the device wakes up in six clock cycles. 7.2 software bod disable when the brown-out detector (bod) is enabled by bodlevel fuses (see table 19-4 on page 160 ), the bod is actively monitoring the supply vo ltage during a sleep period. in some devices it is possible to save power by disabling the bod by software in power-down and stand-by sleep modes. the sleep mode power consum ption will then be at the same level as when bod is glob- ally disabled by fuses. if bod is disabled by software, the bod function is turned off immediately after entering the sleep mode. upon wake-up from sleep, bod is automatically enabled again. this ensures safe operation in case the v cc level has dropped during the sleep period. when the bod has been disabled, the wake-up time from sleep mode will be approximately 60s to ensure that the bod is working corr ectly before the mcu continues executing code. bod disable is controlled by the bods (bod sleep) bit of mcu control register, see ?mcucr ? mcu control register? on page 36 . writing this bit to one turns off bod in power-down and stand-by, while writing a zero keeps the bod active . the default setting is zero, i.e. bod active. writing to the bods bit is controlled by a timed sequence and an enable bit, see ?mcucr ? mcu control register? on page 36 .
35 8006k?avr?10/10 attiny24/44/84 7.2.1 limitations bod disable functionality has been implemented in the following devices, only: ? attiny24, revision e, and newer ? attiny44, revision d, and newer ? attiny84, revision b, and newer revisions are marked on the device pack age and can be located as follows: ? bottom side of packages 14p3 and 14s1 ? top side of package 20m1 7.3 power reduction register the power reduction register (prr), see ?prr ? power reduction register? on page 37 , pro- vides a method to reduce power consumption by stopping the clock to individual peripherals. the current state of the peripheral is frozen and the i/o registers can not be read or written. resources used by the peripheral when stopping the clock will remain occupied, hence the peripheral should in most cases be disabled be fore stopping the clock. waking up a module, which is done by clearing the bit in prr, puts the module in the same state as before shutdown. module shutdown can be used in idle mode and ac tive mode to significantly reduce the overall power consumption. in all other sleep modes, the clock is already stopped. see ?supply current of i/o modules? on page 185 for examples. 7.4 minimizing power consumption there are several issues to consider when trying to minimize the power consumption in an avr controlled system. in general, sleep modes should be used as much as possible, and the sleep mode should be selected so that as few as possi ble of the device?s functions are operating. all functions not needed should be disabled. in particular, the following modules may need special consideration when trying to achieve th e lowest possible power consumption. 7.4.1 analog to digital converter if enabled, the adc will be enabled in all sleep modes. to save power, the adc should be dis- abled before entering any sleep mode. when the adc is turned off and on again, the next conversion will be an extended conversion. see ?analog to digital converter? on page 132 for details on adc operation. 7.4.2 analog comparator when entering idle mode, the analog comparator should be disabled if not used. when entering adc noise reduction mode, the analog comparat or should be disabled. in the other sleep modes, the analog comparator is automatically di sabled. however, if the analog comparator is set up to use the internal voltage reference as input, the analog comparator should be dis- abled in all sleep modes. ot herwise, the internal volt age reference will be enabled, independent of sleep mode. see ?analog comparator? on page 129 for details on how to config- ure the analog comparator.
36 8006k?avr?10/10 attiny24/44/84 7.4.3 brown-out detector if the brown-out detector is not needed in the application, this module should be turned off. if the brown-out detector is enabled by the bodlevel fuses, it will be enabled in all sleep modes, and hence, always consume power. in the deeper sleep modes, this will contribute significantly to the total current consumption. see ?brown-out detection? on page 41 and ?software bod dis- able? on page 34 for details on how to configure the brown-out detector. 7.4.4 internal voltage reference the internal voltage referenc e will be enabled when needed by the brown-out de tection, the analog comparator or the adc. if these modules are disabled as described in the sections above, the internal voltage refe rence will be disabled and it w ill not be consuming power. when turned on again, the user must allow the reference to start up before the output is used. if the reference is kept on in sleep mode, the output can be used immediately. see ?internal voltage reference? on page 42 for details on the start-up time. 7.4.5 watchdog timer if the watchdog timer is not needed in the application, this module should be turned off. if the watchdog timer is enabled, it will be enabled in all sleep modes, and hence, always consume power. in the deeper slee p modes, this will contribute signific antly to the total current consump- tion. see ?watchdog timer? on page 42 for details on how to configure the watchdog timer. 7.4.6 port pins when entering a sleep mode, all port pins should be configured to use minimum power. the most important thing is then to ensure that no pins drive resistive loads. in sleep modes where both the i/o clock (clk i/o ) and the adc clock (clk adc ) are stopped, the input buffers of the device will be disabled. this ensu res that no power is consumed by the input logic when not needed. in some cases, the input logic is needed for detec ting wake-up conditions, and it will then be enabled. see the section ?digital input enable and sleep modes? on page 58 for details on which pins are enabled. if the input buffer is enabled and the input signal is left floating or has an analog signal level close to v cc /2, the input buffer will use excessive power. for analog input pins, the digital input buffer should be disabled at all times. an analog signal level close to v cc /2 on an input pin can cause significant current even in active mode. digital input buffers can be disabled by writing to the digital input disable register (didr0). see ?didr0 ? digital input disable register 0? on page 150 for details. 7.5 register description 7.5.1 mcucr ? mcu control register the mcu control register contains control bits for power management. ? bit 7 ? bods: bod sleep bod disable functionality is available in some devices, only. see ?limitations? on page 35 . in order to disable bod during sleep (see table 7-1 on page 33 ) the bods bit must be written to logic one. this is controlled by a timed sequence and the enable bit, bo dse in mcucr. first, bit 76543210 bods pud se sm1 sm0 bodse isc01 isc00 mcucr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
37 8006k?avr?10/10 attiny24/44/84 both bods and bodse must be set to one. second, within four clock cycles, bods must be set to one and bodse must be set to zero. the bods bit is active three clock cycles after it is set. a sleep instruction must be executed while bods is active in order to turn off the bod for the actual sleep mode. the bods bit is auto matically cleared after three clock cycles. in devices where sleeping bod has not been implem ented this bit is unused and will always read zero. ? bit 5 ? se: sleep enable the se bit must be written to logic one to make the mcu enter the sleep mode when the sleep instruction is executed. to avoid the mcu enteri ng the sleep mode unless it is the programmer?s purpose, it is recommended to write the sleep enable (se) bit to one just before the execution of the sleep instruction and to clear it immediately af ter waking up. ? bits 4:3 ? sm1, sm0: sleep mode select bits 1:0 these bits select between the three available sleep modes as shown in table 7-2 . note: 1. only recommended with external crystal or resonator selected as clock source ? bit 2 ? bodse: bod sleep enable bod disable functionality is available in some devices, only. see ?limitations? on page 35 . the bodse bit enables setting of bods control bit, as explained on bods bit description. bod disable is controlled by a timed sequence. this bit is unused in devices where software bod disable has not been implemented and will read as zero in those devices. 7.5.2 prr ? power reduction register the power reduction register provides a met hod to reduce power consumption by allowing peripheral clock signals to be disabled. ? bits 7:4 ? res: reserved bits these bits are reserved in the attiny 24/44/84 and will always read as zero. ? bit 3 ? prtim1: power reduction timer/counter1 writing a logic one to this bit shuts down the timer/counter1 module. when the timer/counter1 is enabled, operation will cont inue like before the shutdown. table 7-2. sleep mode select sm1 sm0 sleep mode 00idle 0 1 adc noise reduction 1 0 power-down 1 1 standby (1) bit 7654 3 2 10 ? ? ? ? prtim1 prtim0 prusi pradc prr read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
38 8006k?avr?10/10 attiny24/44/84 ? bit 2 ? prtim0: power reduction timer/counter0 writing a logic one to this bit shuts down the timer/counter0 module. when the timer/counter0 is enabled, operation will cont inue like before the shutdown. ? bit 1 ? prusi: power reduction usi writing a logic one to this bit shuts down t he usi by stopping the clock to the module. when waking up the usi again, the usi should be re initialized to ensure proper operation. ? bit 0 ? pradc: power reduction adc writing a logic one to this bit shuts down the adc. the adc must be disabled before shut down. the analog comparator cannot be used when the adc is shut down.
39 8006k?avr?10/10 attiny24/44/84 8. system control and reset 8.1 resetting the avr during reset, all i/o registers are set to their initial values, and the program starts execution from the reset vector. the instruction placed at the reset vector must be a rjmp ? relative jump ? instruction to the reset handling routine. if the program never enables an interrupt source, the interrupt vectors are not used, and regular program code can be placed at these locations. the circuit diagram in figure 8-1 shows the reset logic. electrical parameters of the reset circuitry are given in table 20-4 on page 177 . figure 8-1. reset logic the i/o ports of the avr are immediately reset to their initial state when a reset source goes active. this does not require any clock source to be running. after all reset sources have gone inactive, a delay counter is invoked, stretching the internal reset. this allows the power to reach a stable level before normal operation starts. the time-out period of the delay counter is defined by the user through the sut and cksel fuses. the dif- ferent selections for the delay period are presented in ?clock sources? on page 25 . mcu status register (mcusr) brown-out reset circuit bodlevel [2..0] delay counters cksel[3:0] ck timeout wdrf borf extrf porf data b u s clock generator spike filter pull-up resistor watchdog oscillator sut[1:0] power-on reset circuit
40 8006k?avr?10/10 attiny24/44/84 8.2 reset sources the attiny24/44/84 has four sources of reset: ? power-on reset. the mcu is reset when the supply voltage is below the power-on reset threshold (v pot ). ? external reset. the mcu is reset when a low level is present on the reset pin for longer than the minimum pulse length when reset function is enabled. ? watchdog reset. the mcu is reset when the watchdog timer period expires and the watchdog is enabled. ? brown-out reset. the mcu is re set when the supply voltage v cc is below the brown-out reset threshold (v bot ) and the brown-out detector is enabled. 8.2.1 power-on reset a power-on reset (por) pulse is generated by an on-chip detection circuit. the detection level is defined in ?system and reset characteristics? on page 177 . the por is activated whenever v cc is below the detection level. the por circuit can be used to trigger the start-up reset, as well as to detect a fa ilure in supply voltage. a power-on reset (por) circuit ensures that the device is reset from power-on. reaching the power-on reset threshold voltage invokes the delay counter, which determines how long the device is kept in reset after v cc rise. the reset signal is acti vated again, without any delay, when v cc decreases below the detection level. figure 8-2. mcu start-up, reset tied to v cc figure 8-3. mcu start-up, reset extended externally v re s et time-out internal re s et t tout v pot v r s t cc re s et time-out internal re s et t tout v pot v r s t v cc
41 8006k?avr?10/10 attiny24/44/84 8.2.2 external reset an external reset is generated by a low level on the reset pin if enabled. reset pulses longer than the minimum pulse width (see ?system and reset characteristics? on page 177 ) will gener- ate a reset, even if the clock is not running. shorter pulses are not guaranteed to generate a reset. when the applied signal reaches the reset threshold voltage ? v rst ? on its positive edge, the delay counter starts the mcu after the time-out period ? t tout ? has expired. figure 8-4. external reset during operation 8.2.3 brown-out detection attiny24/44/84 has an on-chip brown-out detection (bod) circuit for monitoring the v cc level during operation by comparing it to a fixed trigger level. the trigger level for the bod can be selected by the bodlevel fuses. the trigger level has a hysteresis to ensure spike free brown-out detection. the hysteresis on the detection level should be interpreted as v bot+ = v bot + v hyst /2 and v bot- = v bot - v hyst /2. when the bod is enabled, and v cc decreases to a value below the trigger level (v bot- in figure 8-5 on page 41 ), the brown-out reset is immediately activated. when v cc increases above the trigger level (v bot+ in figure 8-5 on page 41 ), the delay counter starts the mcu after the time- out period t tout has expired. the bod circuit will only detect a drop in v cc if the voltage stays below the trigger level for lon- ger than t bod given in ?system and reset characteristics? on page 177 . figure 8-5. brown-out reset during operation cc v cc re s et time-out internal re s et v bot- v bot+ t tout
42 8006k?avr?10/10 attiny24/44/84 8.2.4 watchdog reset when the watchdog times out, it will generate a short reset pulse of one ck cycle duration. on the falling edge of this pulse, the delay timer starts counting the time-out period t tout . see ?watchdog timer? on page 42 for details on operation of the watchdog timer. figure 8-6. watchdog reset during operation 8.3 internal voltage reference attiny24/44/84 features an internal bandgap reference. this reference is used for brown-out detection, and it can be used as an input to the analog comparator or the adc. the bandgap voltage varies with supply voltage and temperature. 8.3.1 voltage reference enable signals and start-up time the voltage reference has a start-up time that may influence the way it should be used. the start-up time is given in ?system and reset characteristics? on page 177 . to save power, the reference is not always turned on. the reference is on during the following situations: 1. when the bod is enabled (by pr ogramming the bodl evel [2:0] fuse). 2. when the internal reference is connected to the analog comparator (by setting the acbg bit in acsr). 3. when the adc is enabled. thus, when the bod is not enabled, after setting the acbg bit or enabling the adc, the user must always allow the reference to start up before the output from the analog comparator or adc is used. to reduce power consumption in power-down mode, the user can avoid the three conditions above to ensure that the reference is turned off before entering power-down mode. 8.4 watchdog timer the watchdog timer is clocked fr om an on-chip oscillator which runs at 128 khz. by controlling the watchdog timer prescaler, the watchdog reset interval can be adjusted as shown in table 8-3 on page 47 . the wdr ? watchdog reset ? instruction resets the watchdog timer. the watchdog timer is also reset when it is disabled and when a chip reset occurs. ten different clock cycle periods can be selected to determine the reset period. if the reset period expires without another watchdog reset, the attiny24/44/84 resets and executes from the reset vec- tor. for timing details on the watchdog reset, refer to table 8-3 on page 47 . ck cc
43 8006k?avr?10/10 attiny24/44/84 the wathdog timer can also be configured to generate an interrupt instead of a reset. this can be very helpful when using the watchdog to wake-up from power-down. to prevent unintentional disabling of the watchdog or unintentional change of time-out period, two different safety levels are selected by the fuse wdton as shown in table 8-1 see ?timed sequences for changing the configuration of the watchdog timer? on page 43 for details. figure 8-7. watchdog timer 8.4.1 timed sequences for changing the configuration of the watchdog timer the sequence for changing configuration differs slightly between the two safety levels. separate procedures are described for each level. 8.4.1.1 safety level 1 in this mode, the watchdog time r is initially disabled, but can be enabled by writing the wde bit to one without any restriction. a timed sequence is needed when disabling an enabled watch- dog timer. to disable an enabled watchdog timer, the following procedure must be followed: 1. in the same operation, write a logic one to wdce and wde. a logic one must be writ- ten to wde regardless of the previous value of the wde bit. 2. within the next four clock cycles, in the same operation, write the wde and wdp bits as desired, but with the wdce bit cleared. table 8-1. wdt configuration as a function of the fuse settings of wdton wdton safety level wdt initial state how to disable the wdt how to change time- out unprogrammed 1 disabled timed sequence no limitations programmed 2 enabled always enabled timed sequence osc/2k osc/4k osc/ 8 k osc/16k osc/32k osc/64k osc/12 8 k osc/256k osc/512k osc/1024k mcu reset w atchdog prescaler 12 8 khz oscillator w atchdog reset w dp0 w dp1 w dp2 w dp3 w de mux
44 8006k?avr?10/10 attiny24/44/84 8.4.1.2 safety level 2 in this mode, the watchdog time r is always enabled, and the wde bit will always read as one. a timed sequence is needed when changing the watchdog time-out period. to change the watchdog time-out, the following procedure must be followed: 1. in the same operation, write a logical one to wdce and wde. even though the wde always is set, the wde must be written to one to start the timed sequence. 2. within the next four clock cycles, in the same operation, write the wdp bits as desired, but with the wdce bit cleared. the value written to the wde bit is irrelevant. 8.4.2 code example the following code example shows one assembly and one c function for turning off the wdt. the example assumes that interrupts are controlled (e.g., by disabling interrupts globally) so that no interrupts will occur during execution of these functions. note: see ?code examples? on page 6 . assembly code example wdt_off: wdr ; clear wdrf in mcusr ldi r16, (0< 45 8006k?avr?10/10 attiny24/44/84 8.5 register description 8.5.1 mcusr ? mcu status register the mcu status register provides information on which reset source caused an mcu reset. ? bits 7:4 ? res: reserved bits these bits are reserved bits in the attiny24/44/84 and will always read as zero. ? bit 3 ? wdrf: watchdog reset flag this bit is set if a watchdog re set occurs. the bit is reset by a power-on reset, or by writing a logic zero to the flag. ? bit 2 ? borf: brown-out reset flag this bit is set if a brown-out reset occurs. the bi t is reset by a power-on reset, or by writing a logic zero to the flag. ? bit 1 ? extrf: external reset flag this bit is set if an external reset occurs. the bit is reset by a power-on reset, or by writing a logic zero to the flag. ? bit 0 ? porf: power-on reset flag this bit is set if a power-on reset occurs. the bit is reset only by writing a logic zero to the flag. to make use of the reset flags to identify a reset condition, the user should read and then reset the mcusr as early as possible in the program. if the register is cleared before another reset occurs, the source of the reset can be found by examining the reset flags. 8.5.2 wdtcsr ? watchdog timer control and status register ? bit 7 ? wdif: watchdog timeout interrupt flag this bit is set when a time-out occurs in the watchdog timer and the watchdog timer is config- ured for interrupt. wdif is cleared by hardw are when executing the corresponding interrupt handling vector. alternatively, wdif is cleared by writing a logic one to the flag. when the i-bit in sreg and wdie are set, the watchdog time-out interrupt is executed. ? bit 6 ? wdie: watchdog timeout interrupt enable when this bit is written to one, wde is cleared, and the i-bit in the status register is set, the watchdog time-out interrupt is enabled. in this mode the corresponding interrupt is executed instead of a reset if a timeout in the watchdog timer occurs. if wde is set, wdie is automatically cleared by hardware when a time-out occurs. this is useful for keeping the watchdog reset security while using the interrupt. after the wdie bit is cleared, bit 76543210 0x34 (0x54) ? ? ? ? wdrf borf extrf porf mcusr read/write rrrrr/wr/wr/wr/w initial value 0 0 0 0 see bit description bit 76543210 0x21 (0x41) wdif wdie wdp3 wdce wde wdp2 wdp1 wdp0 wdtcsr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 x 0 0 0
46 8006k?avr?10/10 attiny24/44/84 the next time-out will generate a reset. to avoid the watchdog reset, wdie must be set after each interrupt. ? bit 4 ? wdce: watchdog change enable this bit must be set when the wde bit is writte n to logic zero. otherwis e, the watchdog will not be disabled. once written to one, hardware will clear this bit after four clock cycles. see the description of the wde bit for a watchdog disable procedure. this bit must also be set when changing the prescaler bits. see ?timed sequences for changing the configuration of the watchdog timer? on page 43 . ? bit 3 ? wde: watchdog enable when the wde is written to logic one, the watchdog timer is enabled, and if the wde is written to logic zero, the watchdog timer function is di sabled. wde can only be cleared if the wdce bit has logic level one. to disable an enabled watchdog timer, the following procedure must be followed: 1. in the same operation, write a logic one to wdce and wde. a logic one must be writ- ten to wde even though it is set to one before the disable operation starts. 2. within the next four clock cycles, write a logic 0 to wde. this disables the watchdog. in safety level 2, it is not possible to disable the watchdog timer, even with the algorithm described above. see ?timed sequences for changing the configuration of the watchdog timer? on page 43 . in safety level 1, wde is overridden by wdrf in mcusr. see ?mcusr ? mcu status regis- ter? on page 45 for description of wdrf. this means that wde is always set when wdrf is set. to clear wde, wdrf must be cleared before disabling the watchdog with the procedure described above. this feature ensures multiple re sets during conditions causing failure, and a safe start-up after the failure. note: if the watchdog timer is not going to be used in the application, it is important to go through a watchdog disable procedure in the initialization of the device. if the watchdog is accidentally enabled, for example by a runaway pointer or brown-out condition, the device will be reset, which in turn will lead to a new watchdog reset. to avoi d this situation, the app lication software should always clear the wdrf flag and the wde control bit in the initialization routine. table 8-2. watchdog timer configuration wde wdie watchdog timer state action on time-out 0 0 stopped none 0 1 running interrupt 1 0 running reset 1 1 running interrupt
47 8006k?avr?10/10 attiny24/44/84 ? bits 5, 2:0 ? wdp3:0: watchdog timer prescaler 3, 2, 1, and 0 the wdp3:0 bits determine the watchdog timer prescaling when the watchdog timer is enabled. the different prescaling values and their corresponding timeout periods are shown in table 8-3 . note: 1. if selected, one of the valid settings below 0b1010 will be used. table 8-3. watchdog timer prescale select wdp3 wdp2 wdp1 wdp0 number of wdt oscillator cycles typical time-out at v cc = 5.0v 0 0 0 0 2k cycles 16 ms 0 0 0 1 4k cycles 32 ms 0 0 1 0 8k cycles 64 ms 0 0 1 1 16k cycles 0.125 s 0 1 0 0 32k cycles 0.25 s 0 1 0 1 64k cycles 0.5 s 0 1 1 0 128k cycles 1.0 s 0 1 1 1 256k cycles 2.0 s 1 0 0 0 512k cycles 4.0 s 1 0 0 1 1024k cycles 8.0 s 1010 reserved (1) 1011 1100 1101 1110 1111
48 8006k?avr?10/10 attiny24/44/84 9. interrupts this section describes the specifics of the interrupt handling as performed in attiny24/44/84. for a general explanation of t he avr interrupt handling, see ?reset and interrupt handling? on page 12 . 9.1 interrupt vectors the interrupt vectors of attiny24/44/84 are described in table 9-1 below. if the program never enables an interrupt source, the interrupt vectors are not used, and regular program code can be placed at these locations. the most typical and general setup for reset and interrupt vector addresses in attiny24/44/84 is shown in the program example below. table 9-1. reset and interrupt vectors vector no. program address source interrupt definition 1 0x0000 reset external pin, power-on reset, brown-out reset, watchdog reset 2 0x0001 int0 external interrupt request 0 3 0x0002 pcint0 pin change interrupt request 0 4 0x0003 pcint1 pin change interrupt request 1 5 0x0004 wdt watchdog time-out 6 0x0005 tim1_capt timer/counter1 capture event 7 0x0006 tim1_compa timer/counter1 compare match a 8 0x0007 tim1_compb timer/counter1 compare match b 9 0x0008 tim1_ovf timer/counter1 overflow 10 0x0009 tim0_compa timer/counter0 compare match a 11 0x000a tim0_compb timer/counter0 compare match b 12 0x000b tim0_ovf timer/counter0 overflow 13 0x000c ana_comp analog comparator 14 0x000d adc adc conversion complete 15 0x000e ee_rdy eeprom ready 16 0x000f usi_str usi start 17 0x0010 usi_ovf usi overflow
49 8006k?avr?10/10 attiny24/44/84 address labels code comments 0x0000 rjmp reset ; reset handler 0x0001 rjmp int0 ; irq0 handler 0x0002 rjmp pcint0 ; pcint0 handler 0x0003 rjmp pcint1 ; pcint1 handler 0x0004 rjmp wdt ; watchdog interrupt handler 0x0005 rjmp tim1_capt ; timer1 capture handler 0x0006 rjmp tim1_compa ; timer1 compare a handler 0x0007 rjmp tim1_compb ; timer1 compare b handler 0x0008 rjmp tim1_ovf ; timer1 overflow handler 0x0009 rjmp tim0_compa ; timer0 compare a handler 0x000a rjmp tim0_compb ; timer0 compare b handler 0x000b rjmp tim0_ovf ; timer0 overflow handler 0x000c rjmp ana_comp ; analog comparator handler 0x000d rjmp adc ; adc conversion handler 0x000e rjmp ee_rdy ; eeprom ready handler 0x000f rjmp usi_str ; usi start handler 0x0010 rjmp usi_ovf ; usi overflow handler ; 0x0011 reset: ldi r16, high(ramend); main program start 0x0012 out sph,r16 ; set stack pointer to top of ram 0x0013 ldi r16, low(ramend) 0x0014 out spl,r16 0x0015 sei ; enable interrupts 0x0016 ... ... 9.2 external interrupts the external interrupts are triggered by the int0 pin or any of the pcint11:0 pins. observe that, if enabled, the interrupts will trigger even if the int0 or pcint11:0 pins are configured as outputs. this feature provides a way of generating a software interrupt. pin change 0 interrupts pci0 will trigger if any enabled pcint7:0 pin to ggles. pin change 1 inte rrupts pci1 will trigger if any enabled pcint11:8 pin toggles. the pcmsk0 and pcmsk1 registers control which pins contribute to the pin change interrupts. pin change interrupts on pcint11:0 are detected asyn- chronously. this implies that these interrupts can be used for waking the part also from sleep modes other than idle mode. the int0 interrupts can be triggered by a falling or rising edge or a low level. this is set up as indicated in the specification for the mcu control register ? mcucr. when the int0 interrupt is enabled and is configured as leve l triggered, the interr upt will trigger as long as the pin is held low. note that recognition of falling or rising edge interrupts on int0 requires the presence of an i/o clock, as described in ?clock sources? on page 25 . 9.2.1 low level interrupt a low level interrupt on int0 is detected asyn chronously. this means that the interrupt source can be used for waking the part also from sleep modes other than idle (the i/o clock is halted in all sleep modes except idle).
50 8006k?avr?10/10 attiny24/44/84 note that if a level triggered interrupt is used for wake-up from power-down, the required level must be held long enough for the mcu to complete the wake-up to trigger the level interrupt. if the level disappears before the end of the start-up ti me, the mcu will still wake up, but no inter- rupt will be generated. the start-up time is defined by the sut and cksel fuses, as described in ?clock system? on page 24 . if the low level on the interrupt pin is removed before the device has woken up then program execution will not be diverted to the interrupt service ro utine but continue from the instruction fol- lowing the sleep command. 9.2.2 pin change interrupt timing an example of timing of a pin change interrupt is shown in figure 9-1 . figure 9-1. timing of pin change interrupts clk pcint(0) pin_l a t pin_ s ync pcint_in_(0) pcint_ s yn pcint_ s etfl a g pcif pcint(0) pin_ s ync pcint_ s yn pin_l a t d q le pcint_ s etfl a g pcif clk clk pcint(0) in pcm s k(x) pcint_in_(0) 0 x
51 8006k?avr?10/10 attiny24/44/84 9.3 register description 9.3.1 mcucr ? mcu control register the external interrupt control register a contains control bits for interrupt sense control. ? bits 1:0 ? isc01, isc00: interrupt sense control 0 bit 1 and bit 0 the external interrupt 0 is activated by the exte rnal pin int0 if the sreg i-flag and the corre- sponding interrupt mask are set. the level and edges on the external int0 pin that activate the interrupt are defined in table 9-2 . the value on the int0 pin is sampled before detecting edges. if edge or toggle interrupt is selected, pulses that last longer than one clock period will generate an interrupt. shorter pulses are not guaranteed to generate an interrupt. if low level interrupt is selected, the low level must be held until the completion of the currently executing instruction to generate an interrupt. 9.3.2 gimsk ? general interrupt mask register ? bits 7, 3:0 ? res: reserved bits these bits are reserved in the attiny 24/44/84 and will always read as zero. ? bit 6 ? int0: external interrupt request 0 enable when the int0 bit is set (one) and the i-bit in the status register (sreg) is set (one), the exter- nal pin interrupt is enabled. the interrupt sense control bits (isc01 and isc00) in the external interrupt control register a (eicra) define whether the external interrupt is activated on rising and/or falling edge of the int0 pin or level sens ed. activity on the pin will cause an interrupt request even if int0 is configured as an output. the corresponding interrupt of external interrupt request 0 is executed from the int0 interrupt vector. ? bit 5 ? pcie1: pin change interrupt enable 1 when the pcie1 bit is set (one) and the i-bit in the status register (sreg) is set (one), pin change interrupt 1 is enabled. any change on any enabled pcint11:8 pin will cause an inter- rupt. the corresponding interrupt of pin change interrupt request is executed from the pci1 interrupt vector. pcint11:8 pins are enabled individually by the pcmsk1 register. bit 76543210 0x35 (0x55) bods pud se sm1 sm0 bodse isc01 isc00 mcucr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 9-2. interrupt 0 sense control isc01 isc00 description 0 0 the low level of int0 generates an interrupt request. 0 1 any logical change on int0 generates an interrupt request. 1 0 the falling edge of int0 generates an interrupt request. 1 1 the rising edge of int0 generates an interrupt request. bit 76543210 0x3b (0x5b) ? int0 pcie1 pcie0 ? ? ? ? gimsk read/write r r/w r/w r/w r r r r initial value 0 0 0 0 0 0 0 0
52 8006k?avr?10/10 attiny24/44/84 ? bit 4 ? pcie0: pin change interrupt enable 0 when the pcie0 bit is set (one) and the i-bit in the status register (sreg) is set (one), pin change interrupt 0 is enabled. any change on an y enabled pcint7:0 pin will cause an interrupt. the corresponding interrupt of pin change interrupt request is executed from the pci0 inter- rupt vector. pcint7:0 pins are enabled individually by the pcmsk0 register. 9.3.3 gifr ? general interrupt flag register ? bits 7, 3:0 ? res: reserved bits these bits are reserved in the attiny 24/44/84 and will always read as zero. ? bit 6 ? intf0: external interrupt flag 0 when an edge or logic change on the int0 pin triggers an interrupt request, intf0 becomes set (one). if the i-bit in sreg and the int0 bit in gimsk are set (o ne), the mcu will jump to the cor- responding interrupt vector. the flag is cleared when the interrupt routine is executed. alternatively, the flag can be cleared by writing a logical one to it. this flag is always cleared when int0 is configured as a level interrupt. ? bit 5 ? pcif1: pin change interrupt flag 1 when a logic change on any pcint11:8 pin trigge rs an interrupt request, pcif1 becomes set (one). if the i-bit in sreg and the pcie1 bit in gimsk are set (one), the mcu will jump to the corresponding interrupt vector. the flag is cleared when the interrupt routine is executed. alter- natively, the flag can be cleared by writing a logical one to it. ? bit 4 ? pcif0: pin change interrupt flag 0 when a logic change on any pcint7:0 pin trigger s an interrupt request, pcif becomes set (one). if the i-bit in sreg and the pcie0 bit in gimsk are set (one), the mcu will jump to the corresponding interrupt vector. the flag is cleared when the interrupt routine is executed. alter- natively, the flag can be cleared by writing a logical one to it. 9.3.4 pcmsk1 ? pin change mask register 1 ? bits 7:4 ? res: reserved bits these bits are reserved in the attiny 24/44/84 and will always read as zero. ? bits 3:0 ? pcint11:8: pin change enable mask 11:8 each pcint11:8 bit selects whether pin cha nge interrupt is enabled on the corresponding i/o pin. if pcint11:8 is set and the pcie1 bit in gimsk is set, pin change interrupt is enabled on the corresponding i/o pin. if pcint11:8 is cleared, pin change interrupt on the corresponding i/o pin is disabled. bit 76543210 0x3a (0x5a ?intf0pcif1pcif0????gifr read/write r r/w r/w r/w r r r r initial value 0 0 0 0 0 0 0 0 bit 7 6 5 4 3 2 1 0 0x20 (0x40) ? ? ? ? pcint11 pcint10 pcint9 pcint8 pcmsk1 read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
53 8006k?avr?10/10 attiny24/44/84 9.3.5 pcmsk0 ? pin change mask register 0 ? bits 7:0 ? pcint7:0: pin change enable mask 7:0 each pcint7:0 bit selects whether pin change interrupt is enabled on the corresponding i/o pin. if pcint7:0 is set and the pcie0 bit in gimsk is set, pin change interrupt is enabled on the cor- responding i/o pin. if pcint7:0 is cleared, pi n change interrupt on the corresponding i/o pin is disabled. bit 76543210 0x12 (0x32) pcint7 pcint6 pcint5 pcint4 pcint3 pcint2 pcint1 pcint0 pcmsk0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
54 8006k?avr?10/10 attiny24/44/84 10. i/o ports all avr ports have true read-modi fy-write functionality when used as general digital i/o ports. this means that the direction of one port pin can be changed without unintentionally changing the direction of any other pin with the sbi and cbi instructions. the same applies when chang- ing drive value (if configured as output) or enabling/disabling of pull-up resistors (if configured as input). each output buffer has symmetrical drive characteristics with both high sink and source capability. the pin driver is stro ng enough to drive led displays directly. all port pins have indi- vidually selectable pull-up resistors with a suppl y-voltage invariant resistance. all i/o pins have protection diodes to both v cc and ground as indicated in figure 10-1 on page 54 . see ?electri- cal characteristics? on page 174 for a complete list of parameters. figure 10-1. i/o pin equivalent schematic all registers and bit references in this section are written in general form. a lower case ?x? repre- sents the numbering letter for the port, and a lower case ?n? represents the bit number. however, when using the register or bit defines in a progr am, the precise form must be used. for example, portb3 for bit no. 3 in port b, here documented generally as portxn. the physical i/o regis- ters and bit locations are listed in ?register description? on page 67 . three i/o memory address locations are allocated for each port, one each for the data register ? portx, data direction register ? ddrx, and the port input pins ? pinx. the port input pins i/o location is read only, while the data register and the data direction register are read/write. however, writing a logic one to a bit in the pinx register, will result in a toggle in the correspond- ing bit in the data register. in addition, the pu ll-up disable ? pud bit in mcucr disables the pull-up function for all pins in all ports when set. using the i/o port as general digital i/o is described in ?ports as general digital i/o? on page 55 . most port pins are multiplexed with alternate functions for the peripheral features on the device. how each alternate function interferes with the port pin is described in ?alternate port functions? on page 58 . refer to the individual module sectio ns for a full description of the alter- nate functions. note that enabling the alternate function of some of the port pins does not affect the use of the other pins in the port as general digital i/o. c pin logic r p u s ee fig u re "gener a l digit a l i/o" for det a il s pxn
55 8006k?avr?10/10 attiny24/44/84 10.1 ports as gener al digital i/o the ports are bi-directional i/o ports with optional internal pull-ups. figure 10-2 shows a func- tional description of one i/o-port pin, here generically called pxn. figure 10-2. general digital i/o (1) note: 1. wrx, wpx, wdx, rrx, rpx, and rdx are co mmon to all pins within the same port. clk i/o , sleep, and pud are common to all ports. 10.1.1 configuring the pin each port pin consists of three register bits: ddxn, portxn, and pinxn. as shown in ?register description? on page 67 , the ddxn bits are accessed at the ddrx i/o address, the portxn bits at the portx i/o address, and the pinxn bits at the pinx i/o address. the ddxn bit in the ddrx register selects the direct ion of this pin. if ddxn is written logic one, pxn is configured as an output pin. if ddxn is written logic zero, pxn is configured as an input pin. if portxn is written logic one when the pin is c onfigured as an input pin, the pull-up resistor is activated. to switch the pull-up resistor off, portxn has to be written logic zero or the pin has to be configured as an output pin. the port pins are tri-stated when reset condition becomes active, even if no clocks are running. if portxn is written logic one when the pin is conf igured as an output pin, the port pin is driven high (one). if portxn is written logic zero when the pin is configured as an output pin, the port pin is driven low (zero). clk rpx rrx rdx wdx pud synchronizer wdx: write ddrx wrx: write portx rrx: read portx register rpx: read portx pin pud: pullup disable clk i/o : i/o clock rdx: read ddrx d l q q reset reset q q d q q d clr portxn q q d clr ddxn pinxn data b u s sleep sleep: sleep control pxn i/o wpx 0 1 wrx wpx: write pinx register
56 8006k?avr?10/10 attiny24/44/84 10.1.2 toggling the pin writing a logic one to pinxn toggles the value of portxn, independent on the value of ddrxn. note that the sbi instruction can be used to toggle one single bit in a port. 10.1.3 switching between input and output when switching between tri-state ({ddxn, portxn} = 0b00) and output high ({ddxn, portxn} = 0b11), an intermediate state with either pull-up enabled {ddxn, portxn} = 0b01) or output low ({ddxn, portxn} = 0b10) must occur. norma lly, the pull-up enabled state is fully accept- able, as a high-impedant enviro nment will not notice the differenc e between a strong high driver and a pull-up. if this is not the case, the pud bit in the mcucr register can be set to disable all pull-ups in all ports. switching between input with pull-up and output low generates the same problem. the user must use either the tri-state ({ddxn, portxn} = 0b00) or the output high state ({ddxn, portxn} = 0b10) as an intermediate step. table 10-1 summarizes the control signals for the pin value. 10.1.4 reading the pin value independent of the setting of data direction bit ddxn, the port pin can be read through the pinxn register bit. as shown in figure 10-2 on page 55 , the pinxn register bit and the preced- ing latch constitute a synchronizer. this is needed to avoid metastability if the physical pin changes value near the edge of the internal clock, but it also introduces a delay. figure 10-3 shows a timing diagram of the synchronization when reading an externally applied pin value. the maximum and minimum propagation delays are denoted t pd,max and t pd,min respectively. figure 10-3. synchronization when reading an externally applied pin value table 10-1. port pin configurations ddxn portxn pud (in mcucr) i/o pull-up comment 0 0 x input no tri-state (hi-z) 0 1 0 input yes pxn will source current if ext. pulled low 0 1 1 input no tri-state (hi-z) 1 0 x output no output low (sink) 1 1 x output no output high (source) xxx in r17, pinx 0x00 0xff in s truction s s ync latch pinxn r17 xxx s y s tem clk t pd, m a x t pd, min
57 8006k?avr?10/10 attiny24/44/84 consider the clock period starting shortly after the first falling edge of the system cl ock. the latch is closed when the clock is low, and goes transpa rent when the clock is high, as indicated by the shaded region of the ?sync latch? signal. the signal value is latched when the system clock goes low. it is clocked into the pinxn register at the succeeding positive clock edge. as indi- cated by the two arrows tpd,max and tpd,min, a single signal tr ansition on the pin will be delayed between ? and 1? system clock period depending upon the time of assertion. when reading back a software assigned pin value, a nop instruction must be inserted as indi- cated in figure 10-4 on page 57 . the out instruction sets the ?sync latch? signal at the positive edge of the clock. in this case, the delay tpd through the synchronizer is one system clock period. figure 10-4. synchronization when reading a software assigned pin value the following code example shows how to set port a pins 0 and 1 high, 2 and 3 low, and define the port pins from 4 to 5 as input with a pull-up assigned to port pin 4. the resulting pin values are read back again, but as previously discussed, a nop instruction is included to be able to read back the value recently assigned to some of the pins. note: two temporary registers are used to minimize the time from pull-ups are set on pins 0, 1 and 4, until the direction bits are correctly set, defining bit 2 and 3 as low and redefining bits 0 and 1 as strong high drivers. assembly code example ... ; define pull-ups and set outputs high ; define directions for port pins ldi r16,(1< 58 8006k?avr?10/10 attiny24/44/84 note: see ?code examples? on page 6 . 10.1.5 digital input enable and sleep modes as shown in figure 10-2 on page 55 , the digital input signal can be clamped to ground at the input of the schmitt-trigger. th e signal denoted sleep in the fi gure, is set by the mcu sleep controller in power-down and standby modes to avoid high power consumption if some input signals are left floating, or have an analog signal level close to v cc /2. sleep is overridden for port pins enabled as ex ternal interrupt pins. if the external interrupt request is not e nabled, sleep is active also for these pins. sl eep is also overri dden by various other alternate functions as described in ?alternate port functions? on page 58 . if a logic high level (?one?) is present on an asynchronous external interrupt pin configured as ?interrupt on rising edge, falling edge, or any logic change on pin? while the external interrupt is not enabled, the corresponding external interrupt flag will be set when resuming from the above mentioned sleep mode, as the clamping in these sleep mode produces the requested logic change. 10.1.6 unconnected pins if some pins are unused, it is recommended to ens ure that these pins have a defined level. even though most of the digital inputs are disabled in the deep sleep modes as described above, float- ing inputs should be avoided to reduce current consumption in all other modes where the digital inputs are enabled (reset, active mode and idle mode). the simplest method to ensure a defined level of an unused pin, is to enable the internal pull-up. in this case, the pull-up will be disabled during reset. if low po wer consumption during reset is important, it is recommended to use an external pull-up or pulldown. connecting unused pins directly to v cc or gnd is not recommended, since this ma y cause excessive curr ents if the pin is accidentally configured as an output. 10.2 alternate port functions most port pins have alternate functions in addition to being general digital i/os. in figure 10-5 below is shown how the port pin control signals from the simplified figure 10-2 on page 55 can be overridden by alternate functions. c code example unsigned char i; ... /* define pull-ups and set outputs high */ /* define directions for port pins */ porta = (1< 59 8006k?avr?10/10 attiny24/44/84 figure 10-5. alternate port functions (1) note: 1. wrx, wpx, wdx, rrx, rpx, and rdx are co mmon to all pins within the same port. clk i/o , sleep, and pud are common to all ports. all other signals are unique for each pin. the overriding signals may not be present in a ll port pins, but the figure serves as a generic description applicable to all port pins in the avr microcontroller family. clk rpx rrx wrx rdx wdx pud synchronizer wdx: write ddrx wrx: write portx rrx: read portx register rpx: read portx pin pud: pullup disable clk i/o : i/o clock rdx: read ddrx d l q q set clr 0 1 0 1 0 1 dixn aioxn dieoexn pvovxn pvoexn ddovxn ddoexn puoexn puovxn puoexn: pxn pull-up override enable puovxn: pxn pull-up override value ddoexn: pxn data direction override enable ddovxn: pxn data direction override value pvoexn: pxn port value override enable pvovxn: pxn port value override value dixn: digital input pin n on portx aioxn: analog input/output pin n on portx reset reset q q d clr q q d clr q q d clr pinxn portxn ddxn data b u s 0 1 dieovxn sleep dieoexn: pxn digital input-enable override enable dieovxn: pxn digital input-enable override value sleep: sleep control pxn i/o 0 1 ptoexn ptoexn: pxn, port toggle override enable wpx: write pinx wpx
60 8006k?avr?10/10 attiny24/44/84 table 10-2 summarizes the function of the overriding signals. the pin and port indexes from fig- ure 10-5 are not shown in the succeeding tables. the overriding signals are generated internally in the modules having the alternate function. the following subsections shortly describe the alternate functions for each port, and relate the overriding signals to the alternate function. refer to the alternate function description for further details. table 10-2. generic description of overriding signals for alternate functions signal name full name description puoe pull-up override enable if this signal is set, the pull-u p enable is controlled by the puov signal. if this signal is cleared, the pull-up is enabled when {ddxn, portxn, pud} = 0b010. puov pull-up override value if puoe is set, the pull-up is enabled/disabled when puov is set/cleared, regardless of the setting of the ddxn, portxn, and pud register bits. ddoe data direction override enable if this signal is set, the output driver enable is controlled by the ddov signal. if this signal is cleared, the output driver is enabled by the ddxn register bit. ddov data direction override value if ddoe is set, the output dr iver is enabled/disabled when ddov is set/cleared, regardless of the setting of the ddxn register bit. pvoe port value override enable if this signal is set and the output driver is enabled, the port value is controlled by the pvov signal. if pvoe is cleared, and the output driver is enabled, the port value is controlled by the portxn register bit. pvov port value override value if pvoe is set, the port value is set to pvov, regardless of the setting of the portxn register bit. ptoe port toggle override enable if ptoe is set, the portxn register bit is inverted. dieoe digital input enable override enable if this bit is set, the digital in put enable is controlled by the dieov signal. if this signal is cleared, the digital input enable is determined by mcu state (normal mode, sleep mode). dieov digital input enable override value if dieoe is set, the digital input is enabled/disabled when dieov is set/cleared, regardless of the mcu state (normal mode, sleep mode). di digital input this is the digital input to altern ate functions. in the figure, the signal is connected to the out put of the schmitt-trigger but before the synchronizer. unless the digital input is used as a clock source, the module with the alternate function will use its own synchronizer. aio analog input/output this is the analog input/output to/from alternate functions. the signal is connected directly to the pad, and can be used bi- directionally.
61 8006k?avr?10/10 attiny24/44/84 10.2.1 alternate functions of port a the port a pins with alternate function are shown in table 10-3 . ? port a, bit 0 ? adc0/aref/pcint0 ? adc0: analog to digital converter, channel 0 . ? aref: external analog reference for adc. pullup and output driver are disabled on pa0 when the pin is used as an external reference or internal voltage reference with external capacitor at the aref pin by setting (one) the bit refs0 in the adc multiplexer selection register (admux). ? pcint0: pin change interrupt source 0. the pa0 pin can serve as an external interrupt source for pin change interrupt 0. table 10-3. port a pins alternate functions port pin alternate function pa 0 adc0: adc input channel 0 aref: external analog reference pcint0: pin change interrupt 0, source 0 pa 1 adc1: adc input channel 1 ain0: analog comparator, positive input pcint1:pin change interrupt 0, source 1 pa 2 adc2: adc input channel 2 ain1: analog comparator, negative input pcint2: pin change interrupt 0, source 2 pa 3 adc3: adc input channel 3 t0: timer/counter0 clock source. pcint3: pin change interrupt 0, source 3 pa 4 adc4: adc input channel 4 usck: usi clock (three wire mode) scl : usi clock (two wire mode) t1: timer/counter1 clock source pcint4: pin change interrupt 0, source 4 pa 5 adc5: adc input channel 5 do: usi data output (three wire mode) miso: spi master data input / slave data output oc1b: timer/counter1 compare match b output pcint5: pin change interrupt 0, source 5 pa 6 adc6: adc input channel 6 di: usi data input (three wire mode) sda: usi data input (two wire mode) mosi: spi master data output / slave data input oc1a: timer/counter1 compare match a output pcint6: pin change interrupt 0, source 6 pa 7 adc7: adc input channel 7 oc0b: timer/counter0 compare match b output icp1: timer/counter1 input capture pin pcint7: pin change interrupt 0, source 7
62 8006k?avr?10/10 attiny24/44/84 ? port a, bit 1 ? adc1/ain0/pcint1 ? adc1: analog to digital converter, channel 1 . ? ain0: analog comparator positive input. configure the port pin as input with the internal pull- up switched off to avoid the digital port function from interfering with the function of the analog comparator. ? pcint1: pin change interrupt source 1. the pa1 pin can serve as an external interrupt source for pin change interrupt 0. ? port a, bit 2 ? adc2/ain1/pcint2 ? adc2: analog to digital converter, channel 2 . ? ain1: analog comparator negative input. configure the port pin as input with the internal pull-up switched off to avoid the digital port function from interfering with the function of the analog comparator. ? pcint2: pin change interrupt source 2. the pa2 pin can serve as an external interrupt source for pin change interrupt 0. ? port a, bit 3 ? adc3/t0/pcint3 ? adc3: analog to digital converter, channel 3 . ? t0: timer/counter0 counter source. ? pcint3: pin change interrupt source 3. the pa3 pin can serve as an external interrupt source for pin change interrupt 0. ? port a, bit 4 ? adc4/usck/scl/t1/pcint4 ? adc4: analog to digital converter, channel 4 . ? usck: three-wire mode univer sal serial interface clock. ? scl: two-wire mode serial clock for usi two-wire mode. ? t1: timer/counter1 counter source. ? pcint4: pin change interrupt source 4. the pa4 pin can serve as an external interrupt source for pin change interrupt 0. ? port a, bit 5 ? adc5/do/miso/oc1b/pcint5 ? adc5: analog to digital converter, channel 5 . ? do: data output in usi three-wire mode. data output (do) overrides porta5 value and it is driven to the port when the data direction bit dda5 is set (one). however the porta5 bit still controls the pullup, enab ling pullup if direction is in put and porta5 is set(one). ? miso: master data input, slave data output pin for spi channel. when the spi is enabled as a master, this pin is configured as an input regardless of the setting of dda5. when the spi is enabled as a slave, the data direction of this pin is controlled by dda5. when the pin is forced by the spi to be an input, the pull-up can still be controlled by the porta5 bit. ? oc1b: output compare match output: the pa5 pin can serve as an external output for the timer/counter1 compare match b. the pa5 pin has to be configured as an output (dda5 set (one)) to serve this function. the oc1b pin is also the output pin for the pwm mode timer function. ? pcint5: pin change interrupt source 5. the pa5 pin can serve as an external interrupt source for pin change interrupt 0.
63 8006k?avr?10/10 attiny24/44/84 ? port a, bit 6 ? adc6/di/sda/mosi/oc1a/pcint6 ? adc6: analog to digital converter, channel 6 . ? sda: two-wire mode serial interface data. ? di: data input in usi three-wire mode. usi th ree-wire mode does not override normal port functions, so pin must be configure as an input for di function. ? mosi: master data output, slave data input for spi channel. when the spi is enabled as a slave, this pin is configured as an input regardless of the setting of dda6. when the spi is enabled as a master, the data direction of this pin is controlled by dda6. when the pin is forced by the spi to be an input, the pull-up can still be controlled by the porta6 bit. ? oc1a, output compare match output: the pa6 pin can serve as an external output for the timer/counter1 compare match a. the pin has to be configured as an output (dda6 set (one)) to serve this function. this is also the output pin for the pwm mode timer function. ? pcint6: pin change interrupt source 6. the pa6 pin can serve as an external interrupt source for pin change interrupt 0. ? port a, bit 7 ? adc7/oc0b/icp1/pcint7 ? adc7: analog to digital converter, channel 7 . ? oc0b, output compare match output: the pa7 pin can serve as an external output for the timer/counter0 compare match b. the pin has to be configured as an output (dda7 set (one)) to serve this function. this is also the output pin for the pwm mode timer function. ? icp1, input capture pin: the pa7 pin can act as an input capture pin for timer/counter1. ? pcint7: pin change interrupt source 7. the pa7 pin can serve as an external interrupt source for pin change interrupt 0. table 10-4 and table 10-6 relate the alternate functions of port a to the overriding signals shown in figure 10-5 on page 59 . table 10-4. overriding signals for alternate functions in pa7:pa5 signal name pa7/adc7/oc0b/icp1/ pcint7 pa6/adc6/di/sda/mosi/ oc1a/ pcint6 pa5/adc5/miso/do/ oc1b/ pcint5 puoe 0 0 0 puov 0 0 0 ddoe 0 usiwm1 0 ddov 0 (sda + porta6 ) ? dda6 0 pvoe oc0b enable (usiwm1 ? dda6) + oc1a enable (usiwm1 ? usiwm0) + oc1b enable pvov oc0b ( usiwm1 ? dda6) ? oc1a usiwm1 ? usiwm0 ? do + (usiwm1 + usiwm0 ) ? oc1b ptoe 0 0 0 dieoe pcint7 ? pcie0 + adc7d usisie + (pcint6 ? pcie0) + adc6d pcint5 ? pcie + adc5d dieov pcint7 ? pcie0 usisie + pcint7 ? pcie0 pcint5 ? pcie di pcint7/icp1 input di/sda/pcint6 input pcint5 input aio adc7 input adc6 input adc5 input
64 8006k?avr?10/10 attiny24/44/84 table 10-5. overriding signals for alternate functions in pa4:pa2 signal name pa4/adc4/usck/scl/t1/ pcint4 pa3/adc3/t0/pcint3 pa2/adc2/ain1/pcint2 puoe 0 0 0 puov 0 0 0 ddoe usiwm1 0 0 ddov usi_scl_hold + porta4 ) ? dda4 00 pvoe usiwm1 ? dda4 0 0 pvov 0 0 0 ptoe usi_ptoe 0 0 dieoe usisie + (pcint4 ? pcie0) + adc4d (pcint3 ? pcie0) + adc3d pcint2 ? pcie + adc2d dieov usisie + (pcint4 ? pcie0) pcint3 ? pcie0 pcint3 ? pcie0 di usck/scl/t1/pcint4 input pcint1 input pcint0 input aio adc4 input adc3 input adc2/analog comparator negative input table 10-6. overriding signals for alternate functions in pa1:pa0 signal name pa1/adc1/ain0/pcint1 pa0/adc0/aref/pcint0 puoe 0 reset ? (refs1 ? refs0 + refs1 ? refs0) puov 0 0 ddoe 0 reset ? (refs1 ? refs0 + refs1 ? refs0) ddov 0 0 pvoe 0 reset ? (refs1 ? refs0 + refs1 ? refs0) pvov 0 0 ptoe 0 0 dieoe pcint1 ? pcie0 + adc1d pcint0 ? pcie0 + adc0d dieov pcint1 ? pcie0 pcint0 ? pcie0 di pcint1 input pcint0 input aio adc1/analog comparator positive input adc1 input analog reference
65 8006k?avr?10/10 attiny24/44/84 10.2.2 alternate functions of port b the port b pins with alternate function are shown in table 10-7 . ? port b, bit 0 ? xtal1/pcint8 ? xtal1: chip clock oscillator pin 1. used fo r all chip clock sources except internal calibrateble rc oscillator. when used as a clock pin, the pin can not be used as an i/o pin. when using internal calibrata ble rc oscillator as a chip clock source, pb0 serves as an ordinary i/o pin. ? pcint8: pin change interrupt source 8. the pb0 pin can serve as an external interrupt source for pin change interrupt 1. ? clki: clock input from an external clock source, see ?external clock? on page 26 . ? port b, bit 1 ? xtal2/pcint9 ? xtal2: chip clock oscillator pin 2. used as clock pin for all chip clock sources except internal calibrateble rc oscillator and external clock. when used as a clock pin, the pin can not be used as an i/o pin. when using internal calibratable rc oscillator or external clock as a chip clock sources, pb1 serves as an ordinary i/o pin. ? pcint9: pin change interrupt source 9. the pb1 pin can serve as an external interrupt source for pin change interrupt 1. ? port b, bit 2 ? int0/oc0a/ckout/pcint10 ? int0: external interrupt request 0. ? oc0a: output compare match output: the pb2 pin can serve as an external output for the timer/counter0 compare match a. the pb2 pin has to be configured as an output (ddb2 set (one)) to serve this function. the oc0a pin is also the output pin for the pwm mode timer function. ? ckout - system clock output: the system clock can be output on the pb2 pin. the system clock will be output if the ckout fuse is prog rammed, regardless of the portb2 and ddb2 settings. it will also be output during reset. ? pcint10: pin change interrupt source 10. the pb2 pin can serve as an external interrupt source for pin change interrupt 1. table 10-7. port b pins alternate functions port pin alternate function pb0 xtal1: crystal oscillator input pcint8: pin change interrupt 1, source 8 clki: external clock input pb1 xtal2: crystal oscillator output pcint9: pin change interrupt 1, source 9 pb2 int0: external interrupt 0 input oc0a: timer/counter0 compare match a output ckout: system clock output pcint10:pin change interrupt 1, source 10 pb3 reset : reset pin dw: debugwire i/o pcint11:pin change interrupt 1, source 11.
66 8006k?avr?10/10 attiny24/44/84 ? port b, bit 3 ? reset /dw/pcint11 ? reset : external reset input is active low and enabled by unprogramming (?1?) the rstdisbl fuse. pullup is activated and output driver and digital input are deactivated when the pin is used as the reset pin. ? dw: when the debugwire enable (dwen) fuse is programmed and lock bits are unprogrammed, the debugwire system within th e target device is activated. the reset port pin is configured as a wire-and (open-dr ain) bi-directional i/o pin with pull-up enabled and becomes the communication gateway between target and emulator. ? pcint11: pin change interrupt source 11. the pb3 pin can serve as an external interrupt source for pin change interrupt 1. table 10-8 on page 66 and table 10-9 on page 67 relate the alternate functions of port b to the overriding signals shown in figure 10-5 on page 59 . table 10-8. overriding signals for alternate functions in pb3:pb2 signal name pb3/ reset /dw/ pcint11 pb2/int0/oc0a/ckout/pcint10 puoe rstdisbl (1) + debugwire_enable (2) 1. rstdisbl is 1 when the fuse is ?0? (programmed). 2. debugwire is enabled wheb dwen fuse is programmed and lock bits are unprogrammed. ckout puov 1 0 ddoe rstdisbl (1) + debugwire_enable (2) ckout ddov debugwire_enable (2) ? debugwire tr a n s m i t 1 pvoe rstdisbl (1) + debugwire_enable (2) ckout + oc0a enable pvov 0 ckout ? system clock + ckout ? oc0a ptoe 0 0 dieoe rstdisbl (1) + debugwire_enable (2) + pcint11 ? pcie1 pcint10 ? pcie1 + int0 dieov debugwire_enable (2) + (rstdisbl (1) ? pcint11 ? pcie1) pcint10 ? pcie1 + int0 di dw/pcint11 input int0/pcint10 input aio
67 8006k?avr?10/10 attiny24/44/84 10.3 register description 10.3.1 mcucr ? mcu control register ? bit 6 ? pud: pull-up disable when this bit is written to one, the pull-ups in the i/o ports are disabled even if the ddxn and portxn registers are configured to enable the pull-ups ({ddxn, portxn} = 0b01). see ?con- figuring the pin? on page 55 for more details about this feature. 10.3.2 porta ? port a data register 10.3.3 ddra ? port a data direction register table 10-9. overriding signals for alternate functions in pb1:pb0 signal name pb1/xtal2/pcin t9 pb0/xtal1/pcint8 puoe ext_osc (1) 1. ext_osc = crystal oscillator or low frequency crystal oscillator is selected as system clock. ext_clock (2) + ext_osc (1) 2. ext_clock = external clock is selected as system clock. puov 0 0 ddoe ext_osc (1) ext_clock (2) + ext_osc (1) ddov 0 0 pvoe ext_osc (1) ext_clock (2) + ext_osc (1) pvov 0 0 ptoe 0 0 dieoe ext_osc (1) + pcint9 ? pcie1 ext_clock (2) + ext_osc (1) + (pcint8 ? pcie1) dieov ext_osc (1) ? pcint9 ? pcie1 ( ext_clock (2) ? pwr_down ) + (ext_clock (2) ? ext_osc (1) ? pcint8 ? pcie1) di pcint9 input clock/pcint8 input aio xtal2 xtal1 bit 7 6 5 4 3 2 1 0 bods pud se sm1 sm0 bodse isc01 isc00 mcucr read/write r/w r/w r/w r/w r/w r/w r r initial value 0 0 0 0 0 0 0 0 bit 76543210 0x1b (0x3b) porta7 porta6 porta5 porta4 porta3 porta2 porta1 porta0 porta read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x1a (0x3a) dda7 dda6 dda5 dda4 dda3 dda2 dda1 dda0 ddra read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
68 8006k?avr?10/10 attiny24/44/84 10.3.4 pina ? port a input pins 10.3.5 portb ? port b data register 10.3.6 ddrb ? port b data direction register 10.3.7 pinb ? port b input pins bit 76543210 0x19 (0x39) pina7 pina6 pina5 pina4 pi na3 pina2 pina1 pina0 pina read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value n/a n/a n/a n/a n/a n/a n/a n/a bit 76543210 0x18 (0x38) ? ? ? ? portb3 portb2 portb1 portb0 portb read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x17 (0x37) ???? ddb3 ddb2 ddb1 ddb0 ddrb read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x16 (0x36) ???? pinb3 pinb2 pinb1 pinb0 pinb read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 n/a n/a n/a n/a
69 8006k?avr?10/10 attiny24/44/84 11. 8-bit timer/counter0 with pwm 11.1 features ? two independent output compare units ? double buffered outp ut compare registers ? clear timer on compare match (auto reload) ? glitch free, phase correct pulse width modulator (pwm) ? variable pwm period ? frequency generator ? three independent interrupt sources (tov0, ocf0a, and ocf0b) 11.2 overview timer/counter0 is a general purpose 8-bit time r/counter module, with two independent output compare units, and with pwm support. it allows accurate program execution timing (event man- agement) and wave generation. a simplified block diagram of the 8-bit timer/counter is shown in figure 11-1 on page 69 . for the actual placement of i/o pins, refer to figure 1-1 on page 2 . cpu accessible i/o registers, including i/o bits and i/o pins, are shown in bold. the device-specific i/o register and bit loca- tions are listed in the ?register description? on page 80 . figure 11-1. 8-bit timer/counter block diagram clock select timer/counter data b u s ocrna ocrnb = = tcntn waveform generation waveform generation ocna ocnb = fixed top value control logic = 0 top bottom count clear direction tovn (int.req.) ocna (int.req.) ocnb (int.req.) tccrna tccrnb tn edge detector ( from prescaler ) clk tn
70 8006k?avr?10/10 attiny24/44/84 11.2.1 registers the timer/counter (tcnt0) and output compare registers (ocr0a and ocr0b) are 8-bit registers. interrupt request (abbreviated to int.req. in figure 11-1 ) signals are all visible in the timer interrupt flag register (t ifr0). all interrupts are individually masked with the timer inter- rupt mask register (timsk0). tifr0 and timsk0 are not shown in the figure. the timer/counter can be clocked internally, via the prescaler, or by an external clock source on the t0 pin. the clock select logic block controls which clock source and edge the timer/counter uses to increment (or decrement) its value. the timer/counter is inactive when no clock source is selected. the output from the clock select logic is referred to as the timer clock (clk t0 ). the double buffered output compare registers (ocr0a and ocr0b) is compared with the timer/counter value at all times. the result of the compare can be used by the waveform gen- erator to generate a pwm or variable frequency output on the output compare pins (oc0a and oc0b). see ?output compare unit? on page 71 for details. the compare match event will also set the compare flag (ocf0a or ocf0b) which can be used to generate an output compare interrupt request. 11.2.2 definitions many register and bit references in this section are written in general form. a lower case ?n? replaces the timer/counter number, in this case 0. a lower case ?x? replaces the output com- pare unit, in this case compare unit a or compare unit b. howe ver, when using the register or bit defines in a program, the precise form must be used, i.e., tcnt0 for accessing timer/counter0 counter value and so on. the definitions in table 11-1 are also used extensively throughout the document. 11.3 clock sources the timer/counter can be clocked by an internal or an external clock source. the clock source is selected by the clock select logic which is controlled by the clock select (cs02:0) bits located in the timer/counter control register (tccr0b). for details on clock sources and pres- caler, see ?timer/counter prescaler? on page 115 . 11.4 counter unit the main part of the 8-bit timer/counter is the programmable bi-directional counter unit. figure 11-2 on page 71 shows a block diagram of the counter and its surroundings. table 11-1. definitions constant description bottom the counter reaches bottom when it becomes 0x00 max the counter reaches its maximum when it becomes 0xff (decimal 255) top the counter reaches the top when it become s equal to the highest value in the count sequence. the top value can be assigned to be the fixed value 0xff (max) or the value stored in the ocr0a register. the assi gnment depends on the mode of operation
71 8006k?avr?10/10 attiny24/44/84 figure 11-2. counter unit block diagram signal description (internal signals): count increment or decrement tcnt0 by 1. direction select between increment and decrement. clear clear tcnt0 (set all bits to zero). clk t n timer/counter clock, referred to as clk t0 in the following. top signalize that tcnt0 has reached maximum value. bottom signalize that tcnt0 has re ached minimum value (zero). depending of the mode of operation used, the counter is cleared, incremented, or decremented at each timer clock (clk t0 ). clk t0 can be generated from an external or internal clock source, selected by the clock select bits (cs02:0). w hen no clock source is selected (cs02:0 = 0) the timer is stopped. however, the tcnt0 value can be accessed by the cpu, regardless of whether clk t0 is present or not. a cpu write overrides (has priority over) all counter clear or count operations. the counting sequence is determined by the setting of the wgm01 and wgm00 bits located in the timer/counter control register (tccr0a) and the wgm02 bit located in the timer/counter control register b (tccr0b). there are clos e connections between how the counter behaves (counts) and how waveforms are generated on the output compare output oc0a. for more details about advanced counting sequences and waveform generation, see ?modes of opera- tion? on page 74 . the timer/counter overflow flag (tov0) is set according to the mode of operation selected by the wgm01:0 bits. tov0 can be used for generating a cpu interrupt. 11.5 output compare unit the 8-bit comparator continuously compares tcnt0 with the output compare registers (ocr0a and ocr0b). whenever tcnt0 equals ocr0a or ocr0b, the comparator signals a match. a match will set the output compare flag (ocf0a or ocf0 b) at the next timer clock cycle. if the corresponding interrupt is enabled, the output compare flag generates an output compare interrupt. the output compare flag is automatically cleared when the interrupt is exe- cuted. alternatively, the flag can be cleared by software by writing a logical one to its i/o bit location. the waveform generator uses the matc h signal to generate an output according to operating mode set by the wgm02:0 bits and compare output mode (com0x1:0) bits. the max and bottom signals are used by the waveform generator for handling the special cases of the extreme values in some modes of operation. see ?modes of operation? on page 74 . data b u s tcntn control logic co u nt tovn (int.req.) clock s elect top tn edge detector ( from pre s c a ler ) clk tn b ottom direction cle a r
72 8006k?avr?10/10 attiny24/44/84 figure 11-3 shows a block diagram of the output compare unit. figure 11-3. output compare unit, block diagram the ocr0x registers are double buffered when using any of the pulse width modulation (pwm) modes. for the normal and clear timer on compare (ctc) modes of operation, the dou- ble buffering is disabled. the double buffering synchronizes the update of the ocr0x compare registers to either top or bottom of the counting sequence. the synchronization prevents the occurrence of odd-length, non-symmetrical pwm pulses, thereby making the output glitch-free. the ocr0x register access may seem complex, but this is not case. when the double buffering is enabled, the cpu has access to the ocr0x buffer register, and if double buffering is dis- abled the cpu will access the ocr0x directly. 11.5.1 force output compare in non-pwm waveform generation modes, the match output of the comparator can be forced by writing a one to the force out put compare (0x) bit. forcing compare match will not set the ocf0x flag or reload/clear the timer, but the oc0x pin will be updated as if a real compare match had occurred (the com0x1:0 bits settings de fine whether the oc0x pin is set, cleared or toggled). 11.5.2 compare match bloc king by tcnt0 write all cpu write operations to the tcnt0 register will block any compare ma tch that occur in the next timer clock cycle, even when the timer is stopped. this feature allows ocr0x to be initial- ized to the same value as tcnt0 without triggering an interrupt when the timer/counter clock is enabled. 11.5.3 using the output compare unit since writing tcnt0 in any mo de of operation will block all compare matches for one timer clock cycle, there are risks involved when ch anging tcnt0 when using the output compare unit, independently of whether the timer/counter is running or not. if the value written to tcnt0 ocfn x (int.req.) = ( 8 - b it comp a r a tor ) ocrnx ocnx data b u s tcntn wgmn1:0 w a veform gener a tor top focn comnx1:0 b ottom
73 8006k?avr?10/10 attiny24/44/84 equals the ocr0x value, the compare match will be missed, resulting in incorrect waveform generation. similarly, do not write the tcnt0 value equal to bottom when the counter is down-counting. the setup of the oc0x should be performed before setting the data direction register for the port pin to output. the easiest way of setting the oc0x value is to use the force output com- pare (0x) strobe bits in normal mode. the oc0x registers keep their values even when changing between waveform generation modes. be aware that the com0x1:0 bits are not doubl e buffered together with the compare value. changing the com0x1:0 bits will take effect immediately. 11.6 compare match output unit the compare output mode (com0x1:0) bits have two functions. the waveform generator uses the com0x1:0 bits for defining the output compare (oc0x) state at the next compare match. also, the com0x1:0 bits control the oc0x pin output source. figure 11-4 on page 73 shows a simplified schematic of the logic affected by the com0x1:0 bit setting. the i/o registers, i/o bits, and i/o pins in the figure are shown in bold. only the parts of the general i/o port control registers (ddr and port) that are affected by the com0x1:0 bits are shown. when referring to the oc0x state, the reference is for the inter nal oc0x register, not the oc0x pin. if a system reset occur, the oc0x register is reset to ?0?. figure 11-4. compare match output unit, schematic the general i/o port function is overridden by the output compare (oc0x) from the waveform generator if either of the com0x1:0 bits are set. however, the oc0x pin direction (input or out- put) is still controlled by the da ta direction register (ddr) for th e port pin. the data direction register bit for the oc0x pin (ddr_oc0x) must be set as output before the oc0x value is visi- ble on the pin. the port override function is independent of the waveform generation mode. port ddr dq dq ocn pin ocnx dq w a veform gener a tor comnx1 comnx0 0 1 data b u s focn clk i/o
74 8006k?avr?10/10 attiny24/44/84 the design of the output compare pin logic allows initialization of the oc0x state before the out- put is enabled. note that some com0x1:0 bi t settings are reserved for certain modes of operation, see ?register description? on page 80 11.6.1 compare output mode and waveform generation the waveform generator uses the com0x1:0 bits differently in normal, ctc, and pwm modes. for all modes, setting the com0x1:0 = 0 tells the waveform generator that no action on the oc0x register is to be performed on the next compare match. for compare output actions in the non-pwm modes refer to table 11-2 on page 80 . for fast pwm mode, refer to table 11-3 on page 81 , and for phase correct pwm refer to table 11-4 on page 81 . a change of the com0x1:0 bits state will have effe ct at the first compare match after the bits are written. for non-pwm modes, the action can be forced to have immediate effect by using the 0x strobe bits. 11.7 modes of operation the mode of operation, i.e., the behavior of the timer/counter and the output compare pins, is defined by the combination of the waveform generation mode (wgm02:0) and compare output mode (com0x1:0) bits. the compare output mode bits do not affect the counting sequence, while the waveform generation mode bits do. the com0x1:0 bits control whether the pwm out- put generated should be inverted or not (inverted or non-inverted pwm). for non-pwm modes the com0x1:0 bits control whether the output should be set, cleared, or toggled at a compare match (see ?modes of operation? on page 74 ). for detailed timing information refer to figure 11-8 on page 79 , figure 11-9 on page 79 , figure 11-10 on page 79 and figure 11-11 on page 80 in ?timer/counter timing diagrams? on page 78 . 11.7.1 normal mode the simplest mode of operation is the normal mode (wgm02:0 = 0). in this mode the counting direction is always up (incrementing), and no counter clear is performed. the counter simply overruns when it passes its maximum 8-bit value (top = 0xff) and then restarts from the bot- tom (0x00). in normal o peration the timer/counter overflow flag (tov0) will be set in the same timer clock cycle as the tcnt0 becomes zero. the tov0 flag in this case behaves like a ninth bit, except that it is only set, not cleared. however, combined with the timer overflow interrupt that automatically clears the tov0 flag, the timer resolution can be increased by software. there are no special cases to consider in the normal mode, a new counter value can be written anytime. the output compare unit can be used to generate interrupts at some given time. using the out- put compare to generate waveforms in normal mode is not recommended, since this will occupy too much of the cpu time. 11.7.2 clear timer on compare match (ctc) mode in clear timer on compare or ctc mode (wgm 02:0 = 2), the ocr0a register is used to manipulate the counter resolution. in ctc mode the counter is cleared to zero when the counter value (tcnt0) matches the ocr0a. the ocr0a defines the top value for the counter, hence also its resolution. this mode allows greater control of the compare match output frequency. it also simplifies the operation of counting external events.
75 8006k?avr?10/10 attiny24/44/84 the timing diagram for the ctc mode is shown in figure 11-5 on page 75 . the counter value (tcnt0) increases until a compare match occurs between tcnt0 and ocr0a, and then coun- ter (tcnt0) is cleared. figure 11-5. ctc mode, timing diagram an interrupt can be generated each time the counter value reaches the top value by using the ocf0a flag. if the interrupt is enabled, the interrupt handler routine can be used for updating the top value. however, changing top to a va lue close to bottom when the counter is run- ning with none or a low prescaler value must be done with care since the ctc mode does not have the double buffering feature. if the new value written to ocr0a is lower than the current value of tcnt0, the counter will miss the compar e match. the counter will then have to count to its maximum value (0xff) and wrap around starting at 0x00 before the compare match can occur. for generating a waveform output in ctc mode, the oc0a output can be set to toggle its logical level on each compare match by setting the compare output mode bits to toggle mode (com0a1:0 = 1). the oc0a value will not be visible on the port pin unless the data direction for the pin is set to output. the waveform ge nerated will have a ma ximum frequency of 0 = f clk_i/o /2 when ocr0a is set to zero (0x00). the waveform frequency is defined by the following equation: the n variable represents the prescale factor (1, 8, 64, 256, or 1024). as for the normal mode of operation, the tov0 flag is set in the same timer clock cycle that the counter counts from max to 0x00. 11.7.3 fast pwm mode the fast pulse width modulation or fast pwm mode (wgm02:0 = 3 or 7) provides a high fre- quency pwm waveform generation option. the fast pwm differs from the other pwm option by its single-slope operation. the counter counts from bottom to top then restarts from bot- tom. top is defined as 0xff when wgm2:0 = 3, and ocr0a when wgm2:0 = 7. in non- inverting compare output mode, the output compare (oc0x) is cleared on the compare match between tcnt0 and ocr0x, and set at bottom. in inverting compare output mode, the out- put is set on compare match and cleared at bottom. due to the single-slope operation, the operating frequency of the fast pwm mode can be twice as high as the phase correct pwm mode that use dual-slope operation. this high frequency makes the fast pwm mode well suited tcntn ocn (toggle) ocnx interr u pt fl a g s et 1 4 period 2 3 (comnx1:0 = 1) f ocnx f clk_i/o 2 n 1 ocrnx + () ?? ------------------------------------------------- - =
76 8006k?avr?10/10 attiny24/44/84 for power regulation, rectification, and dac app lications. high frequency a llows physically small sized external components (coils, capacitors), and therefore reduces total system cost. in fast pwm mode, the counter is incremented until the counter value matches the top value. the counter is then cleared at the following timer clock cycle. the timing diagram for the fast pwm mode is shown in figure 11-6 on page 76 . the tcnt0 value is in the timing diagram shown as a histogram for illustrating the singl e-slope operation. the diagram includes non- inverted and inverted pwm outputs. the small horizontal line marks on the tcnt0 slopes repre- sent compare matches between ocr0x and tcnt0. figure 11-6. fast pwm mode, timing diagram the timer/counter overflow flag (tov0) is set each time the counter reaches top. if the inter- rupt is enabled, the interrupt handler routine can be used for updating the compare value. in fast pwm mode, the compare unit allows generation of pwm waveforms on the oc0x pins. setting the com0x1:0 bits to two will produce a non-inverted pwm and an inverted pwm output can be generated by setting the com0x1:0 to three: setting the com0a1:0 bits to one allowes the ac0a pin to toggle on compare matches if t he wgm02 bit is set. this option is not available for the oc0b pin (see table 11-3 on page 81 ). the actual oc0x value will only be visible on the port pin if the data direction for the port pin is set as output. the pwm waveform is generated by setting (or clearing) the oc0x register at the compare match between ocr0x and tcnt0, and clearing (or setting) the oc0x register at t he timer clock cycle the counter is cleared (changes from top to bottom). the pwm frequency for the output can be calculated by the following equation: the n variable represents the prescale factor (1, 8, 64, 256, or 1024). the extreme values for the ocr0a register represents special cases when generating a pwm waveform output in the fast pwm mode. if the ocr0a is set equal to bottom, the output will be a narrow spike for each max+1 timer clock cycle. setting the ocr0a equal to max will result tcntn ocrnx upd a te a nd tovn interr u pt fl a g s et 1 period 2 3 ocn ocn (comnx1:0 = 2) (comnx1:0 = 3 ) ocrnx interr u pt fl a g s et 4 5 6 7 f ocnxpwm f clk_i/o n 256 ? ------------------ =
77 8006k?avr?10/10 attiny24/44/84 in a constantly high or low output (depending on the polarity of the output set by the com0a1:0 bits.) a frequency (with 50% duty cycle) waveform output in fast pwm mode can be achieved by set- ting oc0x to toggle its logical level on each compare match (com0x1:0 = 1). the waveform generated will have a maximum frequency of 0 = f clk_i/o /2 when ocr0a is set to zero. this fea- ture is similar to the oc0a toggle in ctc mode, except the double buffer feature of the output compare unit is enabled in the fast pwm mode. 11.7.4 phase correct pwm mode the phase correct pwm mode (wgm02:0 = 1 or 5) provides a high resolution phase correct pwm waveform generation option. the phase correct pwm mode is based on a dual-slope operation. the counter counts repeatedly from bottom to top and then from top to bot- tom. top is defined as 0xff when wgm2:0 = 1, and ocr0a when wgm2:0 = 5. in non- inverting compare output mode, the output compare (oc0x) is cleared on the compare match between tcnt0 and ocr0x while upcounting, and set on the compare match while down- counting. in inverting output compare mode, the operation is inverted. the dual-slope operation has lower maximum operation frequency than single slope operation. however, due to the sym- metric feature of the dual-slope pwm modes, these modes are preferred for motor control applications. in phase correct pwm mode the counter is incremented until the counter value matches top. when the counter reaches top, it changes the count direction. the tcnt0 value will be equal to top for one timer clock cycle. the timing diagram for the phase correct pwm mode is shown on figure 11-7 on page 77 . the tcnt0 value is in the timing diagram shown as a histogram for illustrating the dual-sl ope operation. the diagram includes non-invert ed and inverted pwm out- puts. the small horizontal line marks on the tcnt0 slopes represent compare matches between ocr0x and tcnt0. figure 11-7. phase correct pwm mode, timing diagram tovn interr u pt fl a g s et ocnx interr u pt fl a g s et 1 2 3 tcntn period ocn ocn (comnx1:0 = 2) (comnx1:0 = 3 ) ocrnx upd a te
78 8006k?avr?10/10 attiny24/44/84 the timer/counter overflow flag (tov0) is set each time the counter reaches bottom. the interrupt flag can be used to generate an interrupt each time the counter reaches the bottom value. in phase correct pwm mode, the compare unit allows generation of pwm waveforms on the oc0x pins. setting the com0x1:0 bits to two will produce a non-inverted pwm. an inverted pwm output can be generated by setting the com0x1:0 to three: setting the com0a0 bits to one allows the oc0a pin to toggle on compare ma tches if the wgm02 bit is set. this option is not available for the oc0b pin (see table 11-4 on page 81 ). the actual oc0x value will only be visible on the port pin if the data direction for th e port pin is set as output. the pwm waveform is generated by clearing (or setting) the oc0x register at the compare match between ocr0x and tcnt0 when the counter increments, and setti ng (or clearing) the oc0x register at com- pare match between ocr0x and tcnt0 when the counter decrements. the pwm frequency for the output when using phase correct pwm can be calculated by the following equation: the n variable represents the prescale factor (1, 8, 64, 256, or 1024). the extreme values for the ocr0a register represent special cases when generating a pwm waveform output in the phase correct pwm mode. if the ocr0a is set equal to bottom, the output will be continuously low an d if set equal to max the output will be continuously high for non-inverted pwm mode. for in verted pwm the output will have the opposite logic values. at the very start of period 2 in figure 11-7 on page 77 ocn has a transition from high to low even though there is no compare match. the point of this transition is to guaratee symmetry around bottom. there are two cases that give a transition without compare match. ? ocr0a changes its value from max, like in figure 11-7 on page 77 . when the ocr0a value is max the ocn pin value is the same as the result of a down-counting compare match. to ensure symmetry around bottom the ocn value at max must correspond to the result of an up-counting compare match. ? the timer starts counting from a value higher than the one in ocr0a, and for that reason misses the compare match and hence the ocn change that would have happened on the way up. 11.8 timer/counter timing diagrams the timer/counter is a synchronous design and the timer clock (clk t0 ) is therefore shown as a clock enable signal in the following figures. the figures include information on when interrupt flags are set. figure 11-8 on page 79 contains timing data for basic timer/counter operation. the figure shows the count sequence close to the max value in all modes other than phase cor- rect pwm mode. f ocnxpcpwm f clk_i/o n 510 ? ------------------ =
79 8006k?avr?10/10 attiny24/44/84 figure 11-8. timer/counter timing diagram, no prescaling figure 11-9 on page 79 shows the same timing data, but with the prescaler enabled. figure 11-9. timer/counter timing dia gram, with prescaler (f clk_i/o /8) figure 11-10 on page 79 shows the setting of ocf0b in all modes and ocf0a in all modes except ctc mode and pwm mode, where ocr0a is top. figure 11-10. timer/counter timing diagram, setting of ocf0x, with prescaler (f clk_i/o /8) figure 11-11 on page 80 shows the setting of ocf0a and the clearing of tcnt0 in ctc mode and fast pwm mode where ocr0a is top. clk tn (clk i/o /1) tovn clk i/o tcntn max - 1 max bottom bottom + 1 tovn tcntn max - 1 max bottom bottom + 1 clk i/o clk tn (clk i/o / 8 ) ocfnx ocrnx tcntn ocrnx v a l u e ocrnx - 1 ocrnx ocrnx + 1 ocrnx + 2 clk i/o clk tn (clk i/o / 8 )
80 8006k?avr?10/10 attiny24/44/84 figure 11-11. timer/counter timing diagram, clear timer on compare match mode, with pres- caler (f clk_i/o /8) 11.9 register description 11.9.1 tccr0a ? timer/counter control register a ? bits 7:6 ? com0a1, com0a0: compare match output a mode these bits control the output compare pin (oc0a) behavior. if one or both of the com0a1:0 bits are set, the oc0a output overrides the normal po rt functionality of the i/o pin it is connected to. however, note that the data direction r egister (ddr) bit corresponding to the oc0a pin must be set in order to enable the output driver. when oc0a is connected to the pin, the function of the com0a1:0 bits depends on the wgm02:0 bit setting. table 11-2 shows the com0a1:0 bit functionality when the wgm02:0 bits are set to a normal or ctc mode (non-pwm). table 11-3 shows com0a1:0 bit functionality when wgm01:0 bits are set to fast pwm mode. ocfnx ocrnx tcntn (ctc) top top - 1 top bottom bottom + 1 clk i/o clk tn (clk i/o / 8 ) bit 7 6 5 4 3 2 1 0 0x30 (0x50) com0a1 com0a0 com0b1 com0b0 ? ? wgm01 wgm00 tccr0a read/write r/w r/w r/w r/w r r r/w r/w initial value 0 0 0 0 0 0 0 0 table 11-2. compare output mode, non-pwm mode com0a1 com0a0 description 0 0 normal port operation, oc0a disconnected. 0 1 toggle oc0a on compare match 1 0 clear oc0a on compare match 1 1 set oc0a on compare match
81 8006k?avr?10/10 attiny24/44/84 note: 1. a special case occurs when ocr0a equals top and com0a1 is set. in this case, the com- pare match is ignored, but the set or clear is done at bottom. see ?fast pwm mode? on page 75 for more details. table 11-4 shows the com0a1:0 bit functionality when the wgm02:0 bits are set to phase cor- rect pwm mode. note: 1. a special case occurs when ocr0a equals top and com0a1 is set. in this case, the com- pare match is ignored, but the set or clear is done at top. see ?phase correct pwm mode? on page 77 for more details. ? bits 5:4 ? com0b1, com0b:0: compare match output b mode these bits control the output compare pin (oc0b) behavior. if one or both of the com0b1:0 bits are set, the oc0b output overrides the normal po rt functionality of the i/o pin it is connected to. however, note that the data direction r egister (ddr) bit corresponding to the oc0b pin must be set in order to enable the output driver. when oc0b is connected to the pin, the function of the com0b1:0 bits depends on the wgm02:0 bit setting. table 11-5 shows the com0b1:0 bit functionality when the wgm02:0 bits are set to a normal or ctc mode (non-pwm). table 11-3. compare output mode, fast pwm mode (1) com0a1 com0a0 description 0 0 normal port operation, oc0a disconnected 01 wgm02 = 0: normal port o peration, oc0a disconnected wgm02 = 1: toggle oc0a on compare match 10 clear oc0a on compare match set oc0a at bottom (non-inverting mode) 11 set oc0a on compare match clear oc0a at bottom (inverting mode) table 11-4. compare output mode, phase correct pwm mode (1) com0a1 com0a0 description 0 0 normal port operation, oc0a disconnected. 01 wgm02 = 0: normal port operation, oc0a disconnected. wgm02 = 1: toggle oc0a on compare match. 10 clear oc0a on compare match when up-counting. set oc0a on compare match when down-counting. 11 set oc0a on compare match when up-counting. clear oc0a on compare match when down-counting. table 11-5. compare output mode, non-pwm mode com0b1 com0b0 description 0 0 normal port operation, oc0b disconnected. 0 1 toggle oc0b on compare match 1 0 clear oc0b on compare match 1 1 set oc0b on compare match
82 8006k?avr?10/10 attiny24/44/84 table 11-6 shows com0b1:0 bit functionality when wgm02:0 bits are set to fast pwm mode. note: 1. a special case occurs when ocr0b equals top and com0b1 is set. in this case, the com- pare match is ignored, but the set or clear is done at bottom. see ?fast pwm mode? on page 75 for more details. table 11-7 shows the com0b1:0 bit functionality when the wgm02:0 bits are set to phase cor- rect pwm mode. note: 1. a special case occurs when ocr0b equals top and com0b1 is set. in this case, the com- pare match is ignored, but the set or clear is done at top. see ?phase correct pwm mode? on page 77 for more details. ? bits 3:2 ? res: reserved bits these bits are reserved in the attiny 24/44/84 and will always read as zero. ? bits 1:0 ? wgm01, wgm00: waveform generation mode combined with the wgm02 bit found in the tccr0b register, these bits control the counting sequence of the counter, the source for maximum (top) counter value, and what type of wave- form generation to be used, see table 11-8 . modes of operation supported by the timer/counter unit are: normal mode (counter), clear timer on compare match (ctc) mode, and two types of pulse width modulation (pwm) modes (see ?modes of operation? on page 74 ). table 11-6. compare output mode, fast pwm mode (1) com0b1 com0b0 description 0 0 normal port operation, oc0b disconnected. 01reserved 10 clear oc0b on compare match, set oc0b at bottom (non-inverting mode) 11 set oc0b on compare match, clear oc0b at bottom (inverting mode) table 11-7. compare output mode, phase correct pwm mode (1) com0b1 com0b0 description 0 0 normal port operation, oc0b disconnected. 01reserved 10 clear oc0b on compare match when up-counting. set oc0b on compare match when down-counting. 11 set oc0b on compare match when up-counting. clear oc0b on compare match when down-counting.
83 8006k?avr?10/10 attiny24/44/84 note: 1. max = 0xff bottom = 0x00 11.9.2 tccr0b ? timer/counter control register b ? bit 7 ? foc0a: force output compare a the foc0a bit is only active when the wgm bits specify a non-pwm mode. however, for ensuring compatibility with future devices, this bit must be set to zero when tccr0b is written when operating in pwm mode. when writing a logical one to the foc0a bit, an immediate compare match is forced on the waveform generation unit. the oc0a output is changed according to its com0a1:0 bits setting. note that the foc0a bit is implemented as a strobe. therefore it is the value present in the com0a1:0 bits that determines the effect of the forced compare. a foc0a strobe will not generate any interrupt, nor will it clear the timer in ctc mode using ocr0a as top. the foc0a bit is always read as zero. ? bit 6 ? foc0b: force output compare b the foc0b bit is only active when the wgm bits specify a non-pwm mode. however, for ensuring compatibility with future devices, this bit must be set to zero when tccr0b is written when operating in pwm mode. when writing a logical one to the foc0b bit, an immediate compare match is forced on the waveform generation unit. the oc0b output is changed according to its com0b1:0 bits setting. note that the foc0b bit is implemented as a strobe. therefore it is the value present in the com0b1:0 bits that determines the effect of the forced compare. table 11-8. waveform generation mode bit description mode wgm02 wgm01 wgm00 timer/counter mode of operation top update of ocrx at tov flag set on (1) 0 0 0 0 normal 0xff immediate max 1001 pwm, phase correct 0xff top bottom 2 0 1 0 ctc ocra immediate max 3 0 1 1 fast pwm 0xff bottom max 4100reserved ? ? ? 5101 pwm, phase correct ocra top bottom 6110reserved ? ? ? 7111fast pwm ocrabottomtop bit 7 6 5 4 3 2 1 0 0x33 (0x53) foc0a foc0b ? ? wgm02 cs02 cs01 cs00 tccr0b read/write w w r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
84 8006k?avr?10/10 attiny24/44/84 a foc0b strobe will not generate any interrupt, nor will it clear the timer in ctc mode using ocr0b as top. the foc0b bit is always read as zero. ? bits 5:4 ? res: reserved bits these bits are reserved bits in the attiny24/44/84 and will always read as zero. ? bit 3 ? wgm02: waveform generation mode see the description in the ?tccr0a ? timer/counter control register a? on page 80 . ? bits 2:0 ? cs02, cs01, cs00: clock select the three clock select bits select the clock source to be used by the timer/counter. if external pin modes are used for the timer/counter0, transitions on the t0 pin will clock the counter even if the pin is configured as an output. this feature allows software control of the counting. 11.9.3 tcnt0 ? timer/counter register the timer/counter register gives direct ac cess, both for read and write operations, to the timer/counter unit 8-bit counter. writing to the tcnt0 register blocks (removes) the compare match on the following timer clock. modifying the counter (tcnt0) while the counter is running, introduces a risk of missing a compare match between tcnt0 and the ocr0x registers. 11.9.4 ocr0a ? output compare register a the output compare register a contains an 8-bi t value that is continuously compared with the counter value (tcnt0). a match can be used to generate an output compare interrupt, or to generate a waveform output on the oc0a pin. table 11-9. clock select bit description cs02 cs01 cs00 description 0 0 0 no clock source (timer/counter stopped) 001clk i/o /(no prescaling) 010clk i/o /8 (from prescaler) 011clk i/o /64 (from prescaler) 100clk i/o /256 (from prescaler) 101clk i/o /1024 (from prescaler) 1 1 0 external clock source on t0 pin. clock on falling edge. 1 1 1 external clock source on t0 pin. clock on rising edge. bit 76543210 0x32 (0x52) tcnt0[7:0] tcnt0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x36 (0x56) ocr0a[7:0] ocr0a read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
85 8006k?avr?10/10 attiny24/44/84 11.9.5 ocr0b ? output compare register b the output compare register b contains an 8-bi t value that is continuously compared with the counter value (tcnt0). a match can be used to generate an output compare interrupt, or to generate a waveform output on the oc0b pin. 11.9.6 timsk0 ? timer/counter 0 interrupt mask register ? bits 7:3 ? res: reserved bits these bits are reserved bits in the attiny24/44/84 and will always read as zero. ? bit 2 ? ocie0b: timer/counter output compare match b interrupt enable when the ocie0b bit is written to one, and the i-bit in the status register is set, the timer/counter compare match b interrupt is enab led. the corresponding interrupt is executed if a compare match in timer/counter occurs, i.e., when the ocf0b bit is set in the timer/counter interrupt flag register ? tifr0. ? bit 1 ? ocie0a: timer/counter0 output compare match a interrupt enable when the ocie0a bit is written to one, and th e i-bit in the status register is set, the timer/counter0 compare match a interrupt is enabled. the corresponding interrupt is executed if a compare match in timer/counter0 occurs, i.e., when the ocf0a bit is set in the timer/counter 0 interrupt flag register ? tifr0. ? bit 0 ? toie0: timer/counter0 overflow interrupt enable when the toie0 bit is written to one, and the i-bit in the status register is set, the timer/counter0 overflow interrupt is enabled. the corresponding interrupt is executed if an overflow in timer/counter0 occurs, i.e., when the tov0 bit is set in the timer/counter 0 inter- rupt flag register ? tifr0. 11.9.7 tifr0 ? timer/counter 0 interrupt flag register ? bits 7:3 ? res: reserved bits these bits are reserved bits in the attiny24/44/84 and will always read as zero. ? bit 2 ? ocf0b: output compare flag 0 b the ocf0b bit is set when a compare match occurs between the timer/counter and the data in ocr0b ? output compare register0 b. ocf0b is cleared by hardware when executing the cor- responding interrupt handling vector. alternatively, ocf0b is cleared by writing a logic one to bit 76543210 0x3c (0x5c) ocr0b[7:0] ocr0b read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543 2 10 0x39 (0x59) ?????ocie0bocie0atoie0timsk0 read/write rrrrrr/wr/wr/w initial value00000 0 00 bit 76543210 0x38 (0x58) ? ? ? ? ? ocf0b ocf0a tov0 tifr0 read/write rrrrrr/wr/wr/w initial value 0 0 0 0 0 0 0 0
86 8006k?avr?10/10 attiny24/44/84 the flag. when the i-bit in sreg, ocie0b (timer/counter compare b match interrupt enable), and ocf0b are set, the timer/counter compare match interrupt is executed. ? bit 1 ? ocf0a: output compare flag 0 a the ocf0a bit is set when a compare match occurs between the timer/counter0 and the data in ocr0a ? output compare register0. ocf0a is cleared by hardware when executing the cor- responding interrupt handling vector. alternativel y, ocf0a is cleared by writing a logic one to the flag. when the i-bit in sreg, ocie0a (timer/counter0 compare match interrupt enable), and ocf0a are set, the timer/counter0 compare match interrupt is executed. ? bit 0 ? tov0: timer/counter0 overflow flag the bit tov0 is set when an overflow occurs in timer/counter0. tov0 is cleared by hardware when executing the corresponding interrupt handling vector. alternatively, tov0 is cleared by writing a logic one to the flag. when the sreg i-bit, toie0 (timer/counter0 overflow interrupt enable), and tov0 are set, the timer/counter0 overflow interrupt is executed. the setting of this flag is dependent of the wgm02:0 bit setting. see table 11-8 on page 83 and ?waveform generation mode bit description? on page 83 .
87 8006k?avr?10/10 attiny24/44/84 12. 16-bit timer/counter1 12.1 features ? true 16-bit design (i.e., allows 16-bit pwm) ? two independent output compare units ? double buffered outp ut compare registers ? one input capture unit ? input capture noise canceler ? clear timer on compare match (auto reload) ? glitch-free, phase correct pu lse width modulator (pwm) ? variable pwm period ? frequency generator ? external event counter ? four independent interrupt sources (tov1, ocf1a, ocf1b, and icf1) 12.2 overview the 16-bit timer/counter unit allows accurate program execution timing (event management), wave generation, and signal timing measurement. a simplified block diagram of the 16-bit timer/counter is shown in figure 12-1 on page 87 . for actual placement of i/o pins, refer to ?pinout attiny24/44/84? on page 2 . cpu accessible i/o registers, including i/o bits and i/o pins, are shown in bold. the device-specific i/o register and bit locations are listed in the ?register description? on page 108 . figure 12-1. 16-bit timer/counter block diagram clock s elect timer/co u nter data b u s ocrna ocrnb icrn = = tcntn w a veform gener a tion w a veform gener a tion ocna ocnb noi s e c a nceler icpn = fixed top v a l u e s edge detector control logic = 0 top bottom co u nt cle a r direction tovn (int.req.) ocna (int.req.) ocnb (int.req.) icfn (int.req.) tccrna tccrnb ( from an a log comp a r a tor o u p u t ) tn edge detector ( from pre s c a ler ) clk tn
88 8006k?avr?10/10 attiny24/44/84 most register and bit references in this sect ion are written in general form. a lower case ?n? replaces the timer/counter number, and a lower case ?x? replaces the output compare unit channel. however, when using the register or bit defines in a program, the precise form must be used, i.e., tcnt1 for accessing timer/counter1 counter value and so on. 12.2.1 registers the timer/counter (tcnt1), output compare registers (ocr1a/b), and input capture regis- ter (icr1) are all 16-bit registers. special procedures must be followed when accessing the 16- bit registers. these procedures are described in the section ?accessing 16-bit registers? on page 105 . the timer/counter control registers (tccr1a/b) are 8-bit registers and have no cpu access restrictions. interrupt requests (abbrevi ated to int.req. in the figure) signals are all visible in the timer interrupt flag register (tifr). all interrupts are individually masked with the timer interrupt mask register (timsk). tifr and timsk are not shown in the figure. the timer/counter can be clocked internally, via the prescaler, or by an external clock source on the t1 pin. the clock select logic block controls which clock source and edge the timer/counter uses to increment (or decrement) its value. the timer/counter is inactive when no clock source is selected. the output from the clock select logic is referred to as the timer clock (clk t 1 ). the double buffered output compare registers (ocr1a/b) are compared with the timer/coun- ter value at all time. the result of the compare can be used by the waveform generator to generate a pwm or variable frequency output on the output compare pin (oc1a/b). see ?out- put compare units? on page 92 . the compare match event will also set the compare match flag (ocf1a/b) which can be used to generate an output compare interrupt request. the input capture register can capture the timer/ counter value at a given external (edge trig- gered) event on either the input capture pin (i cp1) or on the analog comparator pins (see ?analog comparator? on page 129 ). the input capture unit includes a digital filtering unit (noise canceler) for reducing the chance of capturing noise spikes. the top value, or maximum timer/counter value, can in some modes of operation be defined by either the ocr1a register, the icr1 regist er, or by a set of fixed values. when using ocr1a as top value in a pwm mode, the ocr1a register can not be used for generating a pwm output. however, the top value will in this case be do uble buffered allowing the top value to be changed in run time. if a fixed top value is required, the icr1 register can be used as an alternative, freeing the ocr1a to be used as pwm output. 12.2.2 definitions the following definitions are used extensively throughout the section: table 12-1. definitions constant description bottom the counter reaches bottom when it becomes 0x00 max the counter reaches its maximum when it becomes 0xff (decimal 255) top the counter reaches the top when it become s equal to the highest value in the count sequence. the top value can be assigned to be the fixed value 0xff (max) or the value stored in the ocr0a register. the assi gnment depends on the mode of operation
89 8006k?avr?10/10 attiny24/44/84 12.2.3 compatibility the 16-bit timer/counter has been updated and improved from previous versions of 16-bit avr timer/counters. this 16-bit timer/ counter is fully compatible wit h the earlier version regarding: ? all 16-bit timer/counter related i/o register address locations, including timer interrupt registers. ? bit locations inside all 16-bit timer/counter registers, including timer interrupt registers. ? interrupt vectors. the following control bits have changed name, but have same functionality and register location: ? pwm10 is changed to wgm10. ? pwm11 is changed to wgm11. ? ctc1 is changed to wgm12. the following bits are added to the 16-bit timer/counter control registers: ? 1a and 1b are added to tccr1a. ? wgm13 is added to tccr1b. the 16-bit timer/c ounter has improvemen ts that will affect backward compatibility in some spe- cial cases. 12.3 timer/counter clock sources the timer/counter can be clocked by an internal or an external clock source. the clock source is selected by the clock select logic which is controlled by the clock select (cs12:0) bits located in the timer/counter control register b (tccr1b). for details on clock sources and prescaler, see ?timer/counter prescaler? on page 115 . 12.4 counter unit the main part of the 16-bit timer/counter is th e programmable 16-bit bi-directional counter unit. figure 12-2 on page 89 shows a block diagram of the counter and its surroundings. figure 12-2. counter unit block diagram temp ( 8 - b it) data b u s ( 8 - b it) tcntn (16- b it co u nter) tcntnh ( 8 - b it) tcntnl ( 8 - b it) control logic co u nt cle a r direction tovn (int.req.) clock s elect top bottom tn edge detector ( from pre s c a ler ) clk tn
90 8006k?avr?10/10 attiny24/44/84 signal description (internal signals): count increment or decrement tcnt1 by 1. direction select between increment and decrement. clear clear tcnt1 (set all bits to zero). clk t 1 timer/counter clock. top signalize that tcnt1 has reached maximum value. bottom signalize that tcnt1 has re ached minimum value (zero). the 16-bit counter is mapped into two 8-bit i/o memory locations: counter high (tcnt1h) con- taining the upper eight bits of the counter, and counter low (tcnt1l) containing the lower eight bits. the tcnt1h register can only be indirect ly accessed by the cpu. when the cpu does an access to the tcnt1h i/o location, the cpu accesses the high byte temporary register (temp). the temporary register is updated with the tcnt1h value when the tcnt1l is read, and tcnt1h is updated with the temporary register va lue when tcnt1l is written. this allows the cpu to read or write the entire 16-bit counter value within one clock cycle via the 8-bit data bus. it is important to notice that there are special cases of writing to the tcnt1 register when the counter is counting that will gi ve unpredictable results. the s pecial cases are described in the sections where they are of importance. depending on the mode of operation used, the counter is cleared, incremented, or decremented at each timer clock (clk t 1 ). the clk t 1 can be generated from an external or internal clock source, selected by the clock select bits (cs12:0). w hen no clock source is selected (cs12:0 = 0) the timer is stopped. however, the tcnt1 value can be accessed by the cpu, independent of whether clk t 1 is present or not. a cpu write overrides (has priority over) all counter clear or count operations. the counting sequence is determined by the setting of the waveform generation mode bits (wgm13:0) located in the timer/counter c ontrol registers a and b (tccr1a and tccr1b). there are close connections between how the counter behaves (counts) and how waveforms are generated on the output compare outputs oc1x. for more details about advanced counting sequences and waveform generation, see ?modes of operation? on page 96 . the timer/counter overflow flag (tov1) is set according to the mode of operation selected by the wgm13:0 bits. tov1 can be used for generating a cpu interrupt. 12.5 input capture unit the timer/counter incorporates an input capture unit that can capture external events and give them a time-stamp indicating time of occurrence. the external signal indicating an event, or mul- tiple events, can be applied via the icp1 pin or al ternatively, via the analog-comparator unit. the time-stamps can then be used to calculate frequenc y, duty-cycle, and other features of the sig- nal applied. alternatively the time-stamps can be used for creating a log of the events. the input capture unit is illustrate d by the block diagram shown in figure 12-3 on page 91 . the elements of the block diagram that are not directly a part of the input capture unit are gray shaded. the small ?n? in register and bit names indicates the timer/counter number.
91 8006k?avr?10/10 attiny24/44/84 figure 12-3. input capture unit block diagram when a change of the logic level (an event) occurs on the input capture pin (icp1), alternatively on the analog comparator output (aco), and this change confirms to the setting of the edge detector, a capture will be triggered. when a captur e is triggered, the 16-bit value of the counter (tcnt1) is written to the input capture register (icr1). the input capture flag (icf1) is set at the same system clock as the tcnt1 value is copi ed into icr1 register. if enabled (icie1 = 1), the input capture flag generates an input capt ure interrupt. the icf1 flag is automatically cleared when the interrupt is executed. alternativ ely the icf1 flag can be cleared by software by writing a logical one to its i/o bit location. reading the 16-bit value in the input capture register (icr1) is done by first reading the low byte (icr1l) and then the high byte (icr1h). when the low byte is read the high byte is copied into the high byte temporary regi ster (temp). when the cpu reads the icr1h i/o location it will access the temp register. the icr1 register can only be written when us ing a waveform generation mode that utilizes the icr1 register for defining the counter?s top value. in these cases the waveform genera- tion mode (wgm13:0) bits must be set before the top value can be written to the icr1 register. when writing the icr1 re gister the high byte must be written to the icr1h i/o location before the low byte is written to icr1l. for more information on how to access the 16-bit registers refer to ?accessing 16-bit registers? on page 105 . 12.5.1 input capture trigger source the main trigger source for the input capture unit is the input capture pin (icp1). timer/counter1 can alternatively use the analog comparator output as trigger source for the input capture unit. the analog comparator is selected as trigger source by setting the analog icfn (int.req.) an a log comp a r a tor write icrn (16- b it regi s ter) icrnh ( 8 - b it) noi s e c a nceler icpn edge detector temp ( 8 - b it) data b u s ( 8 - b it) icrnl ( 8 - b it) tcntn (16- b it co u nter) tcntnh ( 8 - b it) tcntnl ( 8 - b it) acic* icnc ices aco*
92 8006k?avr?10/10 attiny24/44/84 comparator input capture (acic) bit in the analog comparator control and status register (acsr). be aware that changing trigger source can trigger a capture. the input capture flag must therefore be cleared after the change. both the input capture pin (icp1) and the analog comparator output (aco) inputs are sampled using the same technique as for the t1 pin ( figure 13-1 on page 115 ). the edge detector is also identical. however, when the noise canceler is enabled, additional logic is inserted before the edge detector, which increases t he delay by four system clock cycles. note that the input of the noise canceler and edge detector is always enabl ed unless the timer/counter is set in a wave- form generation mode that uses icr1 to define top. an input capture can be trigger ed by software by controlling the port of the icp1 pin. 12.5.2 noise canceler the noise canceler uses a simple digital filter ing technique to improve noise immunity. consecu- tive samples are monitored in a pipeline four units deep. the signal going to the edge detecter is allowed to change only when all four samples are equal. the noise canceler is enabled by setting the input captur e noise canceler (icnc1) bit in timer/counter control register b (tccr1b). when enabled, the noise canceler introduces an additional delay of four system clock cycles to a change applied to the input and before icr1 is updated. the noise canceler uses the system clock directly and is therefore not affected by the prescaler. 12.5.3 using the input capture unit the main challenge when using the input capture unit is to assign enough processor capacity for handling the incoming events. the time between two events is critical. if the processor has not read the captured value in th e icr1 register before the nex t event occurs, the icr1 will be overwritten with a new value. in this case the result of the ca pture will be incorrect. when using the input capture interrupt, the icr1 register should be read as early in the inter- rupt handler routine as possible. even though the input capture interrupt has relatively high priority, the maximum interrupt response time is dependent on the maximum number of clock cycles it takes to handle any of the other interrupt requests. using the input capture unit in any mode of operation when the top value (resolution) is actively changed during operation, is not recommended. measurement of an external signal?s duty cycle requires that the trigger edge is changed after each capture. changing the edge sensing must be done as early as possible after the icr1 register has been read. after a change of the edge, the input capture flag (icf1) must be cleared by software (writing a logical one to the i/o bit location). for measuring frequency only, the clearing of the icf1 flag is not required (if an interrupt handler is used). 12.6 output compare units the 16-bit comparator continuously compares tcnt1 with the output compare register (ocr1x). if tcnt equals ocr1x the comparator signals a match. a match will set the output compare flag (ocf1x) at the next timer clock cycle. if enabled (ocie1x = 1), the output com- pare flag generates an output compare interrupt. the ocf1x flag is automatically cleared when the interrupt is executed. alternatively the ocf1x flag can be cleare d by software by writ- ing a logical one to its i/o bit location. the waveform generator uses the match signal to generate an output according to operating mode set by the waveform generation mode
93 8006k?avr?10/10 attiny24/44/84 (wgm13:0) bits and compare output mode (com1x1:0) bits. the top and bottom signals are used by the waveform generator for handling the special cases of the extreme values in some modes of operation ( ?modes of operation? on page 96 ). a special feature of output compare unit a allows it to define the timer/counter top value (i.e., counter resolution). in addition to the counter resolution, the top value defines the period time for waveforms generated by the waveform generator. figure 12-4 on page 93 shows a block diagram of the output compare unit. the small ?n? in the register and bit names indicates the device number (n = 1 for timer/counter 1), and the ?x? indi- cates output compare unit (a/b). the elements of the block diagram that are not directly a part of the output compare unit are gray shaded. figure 12-4. output compare unit, block diagram the ocr1x register is double buffered when using any of the twelve pulse width modulation (pwm) modes. for the normal and clear timer on compare (ctc) modes of operation, the double buffering is disabled. the double buffering synchronizes the update of the ocr1x com- pare register to either top or bottom of the counting sequence. the synchronization prevents the occurrence of odd-length, non-symmetrical pwm pulses, thereby making the out- put glitch-free. the ocr1x register access may seem complex, but this is not case. when the double buffering is enabled, the cpu has access to the ocr1x buffer register, and if double buffering is dis- abled the cpu will access the ocr1x directly. the content of the ocr1x (buffer or compare) register is only changed by a write operation (the timer/counter does not update this register automatically as the tcnt1 and icr1 register). therefore ocr1x is not read via the high byte temporary register (temp). however, it is a good practice to read the low byte first as when accessing other 16-bit registers. writing the ocr1x registers must be done via the temp reg- ocfnx (int.req.) = (16- b it comp a r a tor ) ocrnx b u ffer (16- b it regi s ter) ocrnxh b u f. ( 8 - b it) ocnx temp ( 8 - b it) data b u s ( 8 - b it) ocrnxl b u f. ( 8 - b it) tcntn (16- b it co u nter) tcntnh ( 8 - b it) tcntnl ( 8 - b it) comnx1:0 wgmn3:0 ocrnx (16- b it regi s ter) ocrnxh ( 8 - b it) ocrnxl ( 8 - b it) w a veform gener a tor top bottom
94 8006k?avr?10/10 attiny24/44/84 ister since the compare of all 16 bits is done continuously. the high byte (ocr1xh) has to be written first. when the high byte i/o location is written by the cpu, the temp register will be updated by the value written. then when the low by te (ocr1xl) is written to the lower eight bits, the high byte will be copied into the upper 8-bits of either the ocr1x bu ffer or ocr1x compare register in the same system clock cycle. for more information of how to access the 16-bit registers refer to ?accessing 16-bit registers? on page 105 . 12.6.1 force output compare in non-pwm waveform generation modes, the match output of the comparator can be forced by writing a one to the force output compare (1x) bit. forcing compare match will not set the ocf1x flag or reload/clear the timer, but the oc1x pin will be updated as if a real compare match had occurred (the com11:0 bits settings define whether the oc1x pin is set, cleared or toggled). 12.6.2 compare match bloc king by tcnt1 write all cpu writes to the tcnt1 register will block any compare match that o ccurs in the next timer clock cycle, even when the timer is stopped. this feature allows ocr1x to be initialized to the same value as tcnt1 without triggering an inte rrupt when the timer/counter clock is enabled. 12.6.3 using the output compare unit since writing tcnt1 in any mode of operation will block all comp are matches for one timer clock cycle, there are risks involved when changing tcnt1 when using any of the output compare channels, independent of whether the timer/counter is running or not. if the value written to tcnt1 equals the ocr1x value, the compare matc h will be missed, resulting in incorrect wave- form generation. do not write the tcnt1 equal to top in pwm modes with variable top values. the compare match for the top will be ignored and the counte r will continue to 0xffff. similarly, do not write the tcnt1 value equal to bottom when the counter is downcounting. the setup of the oc1x should be performed before setting the data direction register for the port pin to output. the easiest way of setting the oc1x value is to use the force output com- pare (1x) strobe bits in normal mode. the oc1x register keeps its value even when changing between waveform generation modes. be aware that the com1x1:0 bits are not doubl e buffered together with the compare value. changing the com1x1:0 bits will take effect immediately. 12.7 compare match output unit the compare output mode (com1x1:0) bits have two functions. the waveform generator uses the com1x1:0 bits for defining the output compare (oc1x) state at the next compare match. secondly the com1x1:0 bits control the oc1x pin output source. figure 12-5 on page 95 shows a simplified schematic of the logic affected by the com1x1:0 bit setting. the i/o registers, i/o bits, and i/o pins in the figure are shown in bold. only the parts of the general i/o port control registers (ddr and port) that are affected by the com1x1:0 bits are shown. when referring to the oc1x state, the reference is for the internal oc1x register, not the oc1x pin. if a system reset occur, the oc1x register is reset to ?0?.
95 8006k?avr?10/10 attiny24/44/84 figure 12-5. compare match output unit, schematic (non-pwm mode) the general i/o port function is overridden by the output compare (oc1x) from the waveform generator if either of the com1x1:0 bits are set. however, the oc1x pin direction (input or out- put) is still controlled by the data direction register (ddr) for the port pin. the data direction register bit for the oc1x pin (ddr_oc1x) must be set as output before the oc1x value is visi- ble on the pin. the port override function is generally independent of the waveform generation mode, but there are some exceptions. see table 12-2 on page 109 , table 12-3 on page 109 and table 12-4 on page 109 for details. the design of the output compare pin logic allows initialization of the oc1x state before the out- put is enabled. note that some com1x1:0 bi t settings are reserved for certain modes of operation. see ?register description? on page 108 the com1x1:0 bits have no effect on the input capture unit. 12.7.1 compare output mode and waveform generation the waveform generator uses the com1x1:0 bits differently in normal, ctc, and pwm modes. for all modes, setting the com1x1:0 = 0 tells the waveform generator that no action on the oc1x register is to be performed on the next compare match. for compare output actions in the non-pwm modes refer to table 12-2 on page 109 . for fast pwm mode refer to table 12-3 on page 109 , and for phase correct and phase and frequency correct pwm refer to table 12-4 on page 109 . a change of the com1x1:0 bits st ate will have effect at the first compare matc h after the bits are written. for non-pwm modes, the action can be forced to have immediate effect by using the 1x strobe bits. port ddr dq dq ocnx pin ocnx dq w a veform gener a tor comnx1 comnx0 0 1 data b u s focnx clk i/o
96 8006k?avr?10/10 attiny24/44/84 12.8 modes of operation the mode of operation, i.e., the behavior of the timer/counter and the output compare pins, is defined by the combination of the waveform generation mode (wgm13:0) and compare output mode (com1x1:0) bits. the compare output mode bits do not affect the counting sequence, while the waveform generation mode bits do. the com1x1:0 bits control whether the pwm out- put generated should be inverted or not (inverted or non-inverted pwm). for non-pwm modes the com1x1:0 bits control whether the output should be set, cleared or toggle at a compare match ( ?compare match output unit? on page 94 ) for detailed timing information refer to ?timer/counter timing diagrams? on page 103 . 12.8.1 normal mode the simplest mode of operation is the normal mode (wgm13:0 = 0). in this mode the counting direction is always up (incrementing), and no counter clear is performed. the counter simply overruns when it passes its maximum 16-bit value (max = 0xffff) and then restarts from the bottom (0x0000). in normal operation the timer/c ounter overflow flag (tov1) will be set in the same timer clock cycle as the tcnt1 beco mes zero. the tov1 flag in this case behaves like a 17th bit, except that it is only set, not cleared. however, combined with the timer overflow interrupt that automatically clears the tov1 flag, the timer resolution can be increased by soft- ware. there are no special cases to consider in the normal mode, a new counter value can be written anytime. the input capture unit is easy to use in normal mode. however, observe that the maximum interval between the external events must not exceed the resolution of the counter. if the interval between events are too long, the timer overflow interrupt or the prescaler must be used to extend the resolution for the capture unit. the output compare units can be used to generat e interrupts at some given time. using the output compare to gene rate waveforms in norm al mode is not recommended, since this will occupy too much of the cpu time. 12.8.2 clear timer on compare match (ctc) mode in clear timer on compare or ctc mode (wgm13:0 = 4 or 12), the ocr1a or icr1 register are used to manipulate the counter resolution. in ctc mode the counter is cleared to zero when the counter value (tcnt1) matches either the ocr1a (wgm13:0 = 4) or the icr1 (wgm13:0 = 12). the ocr1a or icr1 define the top value for the counter, hence also its resolution. this mode allows greater control of the compare match output frequency. it also simplifies the opera- tion of counting external events. the timing diagram for the ctc mode is shown in figure 12-6 on page 97 . the counter value (tcnt1) increases until a compare match occurs with either ocr1a or icr1, and then counter (tcnt1) is cleared.
97 8006k?avr?10/10 attiny24/44/84 figure 12-6. ctc mode, timing diagram an interrupt can be generated at each time the counter value reaches the top value by either using the ocf1a or icf1 flag according to the register used to define the top value. if the inter- rupt is enabled, the interrupt handler routine can be used for updating the top value. however, changing the top to a value close to bottom w hen the counter is running with none or a low prescaler value must be done with care since the ctc mode does not have the double buffering feature. if the new value written to ocr1a or icr1 is lower than the current value of tcnt1, the counter will miss the compare matc h. the counter will th en have to count to its maximum value (0xffff) and wrap around starting at 0x0000 before the compare match can occur. in many cases this feature is not desirable. an alternative will then be to use the fast pwm mode using ocr1a for defining top (wgm13:0 = 15) si nce the ocr1a then will be double buffered. for generating a waveform output in ctc mode, the oc1a output can be set to toggle its logical level on each compare match by setting the compare output mode bits to toggle mode (com1a1:0 = 1). the oc1a value will not be visible on the port pin unless the data direction for the pin is set to output (ddr_oc1a = 1). th e waveform generated will have a maximum fre- quency of 1 a = f clk_i/o /2 when ocr1a is set to zero (0x0000). the waveform frequency is defined by the following equation: the n variable represents the prescaler factor (1, 8, 64, 256, or 1024). as for the normal mode of operation, the tov1 flag is set in the same timer clock cycle that the counter counts from max to 0x0000. 12.8.3 fast pwm mode the fast pulse width modulation or fast pwm mode (wgm13:0 = 5, 6, 7, 14, or 15) provides a high frequency pwm waveform generation option. the fast pwm differs from the other pwm options by its single-slope operation. the counter counts from bottom to top then restarts from bottom. in non-inverting compare output mode, the output compare (oc1x) is cleared on the compare match between tcnt1 and ocr1x, and set at bottom. in inverting compare output mode output is set on compare match and cleared at bottom. due to the single-slope operation, the operating frequency of the fast pwm mode can be twice as high as the phase cor- rect and phase and frequency correct pwm modes that use dual-slope operation. this high frequency makes the fast pwm mode well suited for power regula tion, rectification, and dac tcntn ocna (toggle) ocna interr u pt fl a g s et or icfn interr u pt fl a g s et (interr u pt on top) 1 4 period 2 3 (comna1:0 = 1) f ocna f clk_i/o 2 n 1 ocrna + () ?? --------------------------------------------------- =
98 8006k?avr?10/10 attiny24/44/84 applications. high frequency allows physically sm all sized external com ponents (coils, capaci- tors), hence reduces total system cost. the pwm resolution for fast pwm can be fixed to 8-, 9-, or 10-bit, or defined by either icr1 or ocr1a. the minimum resolution allowed is 2-bit (icr1 or ocr1a set to 0x0003), and the max- imum resolution is 16-bit (icr1 or ocr1a set to max). the pwm resolution in bits can be calculated by using the following equation: in fast pwm mode the counter is incremented until the counter value matches either one of the fixed values 0x00ff, 0x01ff, or 0x03ff (wgm13:0 = 5, 6, or 7), the value in icr1 (wgm13:0 = 14), or the value in ocr1a (wgm13:0 = 15). the counter is then cleared at the following timer clock cycle. the timing diagram fo r the fast pwm mode is shown in figure 12-7 on page 98 . the figure shows fast pwm mode when ocr1a or icr1 is used to define top. the tcnt1 value is in the timing diagram shown as a histogram for illustrating the single-slope operation. the dia- gram includes non-inverted and inverted pwm outputs. the small horizontal line marks on the tcnt1 slopes represent compare matches between ocr1x and tcnt1. the oc1x interrupt flag will be set when a compare match occurs. figure 12-7. fast pwm mode, timing diagram the timer/counter overflow flag (tov1) is set each time the counter reaches top. in addition the oc1a or icf1 flag is set at the same timer clock cycle as tov1 is set when either ocr1a or icr1 is used for defining the top value. if one of the interrupts are enabled, the interrupt han- dler routine can be used for updating the top and compare values. when changing the top value the program must ensure that the new top value is higher or equal to the value of all of the compare registers. if the top value is lower than any of the compare registers, a compare match will never occur between the tcnt1 and the ocr1x. note that when using fixed top values the unused bits are masked to zero when any of the ocr1x registers are written. the procedure for updating icr1 differs from updating ocr1a when used for defining the top value. the icr1 register is not double buffered. this means that if icr1 is changed to a low r fpwm top 1 + () log 2 () log ---------------------------------- - = tcntn ocrnx/top upd a te a nd tovn interr u pt fl a g s et a nd ocna interr u pt fl a g s et or icfn interr u pt fl a g s et (interr u pt on top) 1 7 period 2 3 4 5 6 8 ocnx ocnx (comnx1:0 = 2) (comnx1:0 = 3 )
99 8006k?avr?10/10 attiny24/44/84 value when the counter is running with none or a low prescaler value, there is a risk that the new icr1 value written is lower than the current va lue of tcnt1. the result will then be that the counter will miss the compare matc h at the top value. the counter will then have to count to the max value (0xffff) and wrap around starting at 0x0000 before the compare match can occur. the ocr1a register however, is double buffered. this feature allows the ocr1a i/o location to be written anytime. when the ocr1a i/o location is written the value written will be put into the ocr1a buffer register. th e ocr1a compare register will th en be updated with the value in the buffer register at the next timer clo ck cycle the tcnt1 matches top. the update is done at the same timer clock cycle as the tcnt1 is cleared and the tov1 flag is set. using the icr1 register for defining top work s well when using fixed top values. by using icr1, the ocr1a register is free to be used for generating a pwm output on oc1a. however, if the base pwm frequency is actively change d (by changing the top value), using the ocr1a as top is clearly a better choice due to its double buffer feature. in fast pwm mode, the compare units allow generation of pwm waveforms on the oc1x pins. setting the com1x1:0 bits to two will produce a non-inverted pwm and an inverted pwm output can be generated by setting the com1x1:0 to three (see table 12-3 on page 109 ). the actual oc1x value will only be visible on the port pin if th e data direction for the po rt pin is set as output (ddr_oc1x). the pwm waveform is generated by setting (or clearing) the oc1x register at the compare match between ocr1x and tcnt1, and clearing (or setting) the oc1x register at the timer clock cycle the counter is cleared (changes from top to bottom). the pwm frequency for the output can be calculated by the following equation: the n variable represents the prescaler divider (1, 8, 64, 256, or 1024). the extreme values for the ocr1x register represents special cases when generating a pwm waveform output in the fast pwm mode. if the ocr1x is set equal to bottom (0x0000) the out- put will be a narrow spike for eac h top+1 timer clock cycle. se tting the ocr1x equal to top will result in a const ant high or low output (depending on the polarity of the output set by the com1x1:0 bits.) a frequency (with 50% duty cycle) waveform output in fast pwm mode can be achieved by set- ting oc1a to toggle its logical level on each compare match (com1a1:0 = 1). the waveform generated will have a ma ximum frequency of 1 a = f clk_i/o /2 when ocr1a is se t to zero (0x0000). this feature is similar to the oc1a toggle in ctc mode, except the double buffer feature of the output compare unit is enabled in the fast pwm mode. 12.8.4 phase correct pwm mode the phase correct pulse width modulation or phase correct pwm mode (wgm13:0 = 1, 2, 3, 10, or 11) provides a high resolution phase correct pwm waveform generation option. the phase correct pwm mode is, like the phase and frequency correct pwm mode, based on a dual- slope operation. the counter counts repeatedly from bottom (0x0000) to top and then from top to bottom. in non-inverting compare output mode, the output compare (oc1x) is cleared on the compare match between tcnt1 and ocr1x while upcounting, and set on the compare match while downcounting. in inverting output compare mode, the operation is inverted. the dual-slope operation has lower maximum operation frequency than single slope operation. however, due to the symmetric feat ure of the dual-slope pwm modes, these modes are preferred for motor control applications. f ocnxpwm f clk_i/o n 1 top + () ? ---------------------------------- - =
100 8006k?avr?10/10 attiny24/44/84 the pwm resolution for the phase correct pwm mode can be fixed to 8-, 9-, or 10-bit, or defined by either icr1 or ocr1a. the minimum resolution allowed is 2-bit (icr1 or ocr1a set to 0x0003), and the maximum resolution is 16-bit (icr1 or ocr1a set to max). the pwm resolu- tion in bits can be calculated by using the following equation: in phase correct pwm mode the counter is incremented until the counter value matches either one of the fixed values 0x00ff, 0x01ff, or 0x03ff (wgm13:0 = 1, 2, or 3), the value in icr1 (wgm13:0 = 10), or the value in ocr1a (wgm13:0 = 11). the counter has then reached the top and changes the count direct ion. the tcnt1 value will be equa l to top for one timer clock cycle. the timing diagram for the phase correct pwm mode is shown on figure 12-8 on page 100 . the figure shows phase correct pwm mode w hen ocr1a or icr1 is used to define top. the tcnt1 value is in the timing diagram shown as a histogram for illustrating the dual-slope operation. the diagram includes non-inverted and inverted pwm outputs. the small horizontal line marks on the tcnt1 slopes represent compare matches between ocr1x and tcnt1. the oc1x interrupt flag will be set when a compare match occurs. figure 12-8. phase correct pwm mode, timing diagram the timer/counter overflow flag (tov1) is set each time the counter reaches bottom. when either ocr1a or icr1 is used for defining the top value, the oc1a or icf1 flag is set accord- ingly at the same timer clock cycle as the ocr1x registers are updated with the double buffer value (at top). the interrupt flags can be used to generate an interrupt each time the counter reaches the top or bottom value. when changing the top value the program must ensure that the new top value is higher or equal to the value of all of the compare registers. if the top value is lower than any of the compare registers, a compare match will never occur between the tcnt1 and the ocr1x. note that when using fixed top values, the unus ed bits are masked to zero when any of the ocr1x registers are written. as the third period shown in figure 12-8 on page 100 illustrates, r pcpwm top 1 + () log 2 () log ---------------------------------- - = ocrnx/top upd a te a nd ocna interr u pt fl a g s et or icfn interr u pt fl a g s et (interr u pt on top) 1 2 3 4 tovn interr u pt fl a g s et (interr u pt on bottom) tcntn period ocnx ocnx (comnx1:0 = 2) (comnx1:0 = 3 )
101 8006k?avr?10/10 attiny24/44/84 changing the top actively while the timer/counter is running in the phase correct mode can result in an unsymmetrical output. the reason for this can be found in the time of update of the ocr1x register. since the ocr1x update occurs at top, the pwm period starts and ends at top. this implies that the length of the falling slope is determined by the previous top value, while the length of the rising slope is determined by the new top value. when these two values differ the two slopes of the period will differ in length. the differ ence in length gives the unsym- metrical result on the output. it is recommended to use the phase and frequency correct mode instead of the phase correct mode when changing the top value while the timer/counter is running. when using a static top value there are practically no differences between the two modes of operation. in phase correct pwm mode, the compare units allow generation of pwm waveforms on the oc1x pins. setting the com1x1:0 bits to tw o will produce a non-inverte d pwm and an inverted pwm output can be generated by setting the com1x1:0 to three (see table 12-4 on page 109 ). the actual oc1x value will only be visible on the port pin if the data direction for the port pin is set as output (ddr_oc1x). the pwm waveform is gene rated by setting (or clearing) the oc1x register at the compare match between ocr1x and tcnt1 when the counter increments, and clearing (or setting) the oc1x register at compare match between ocr1x and tcnt1 when the counter decrements. the pwm frequency for the output when using phase correct pwm can be calculated by the following equation: the n variable represents the prescaler divider (1, 8, 64, 256, or 1024). the extreme values for the ocr1x register represent special cases when generating a pwm waveform output in the phase correct pwm mode. if the ocr1x is set equal to bottom the output will be continuously low and if set equal to top the output will be continuously high for non-inverted pwm mode. for in verted pwm the output will have the opposite logic values. 12.8.5 phase and frequency correct pwm mode the phase and frequency correct pulse width modulation, or phase and frequency correct pwm mode (wgm13:0 = 8 or 9) provides a high reso lution phase and frequency correct pwm wave- form generation option. the phase and frequency correct pwm mode is, like the phase correct pwm mode, based on a dual-slope operation. the counter counts repeatedly from bottom (0x0000) to top and then from top to bottom. in non-inverting compare output mode, the output compare (oc1x) is cleared on the compare match between tcnt1 and ocr1x while upcounting, and set on the compare match while downcounting. in inverting compare output mode, the operation is inverted. the dual-slope operation gives a lower maximum operation fre- quency compared to the single-slope operation. howe ver, due to the symmetric feature of the dual-slope pwm modes, these modes are preferred for motor control applications. the main difference between the phase correct, and the phase and frequency correct pwm mode is the time the ocr1x register is up dated by the ocr1x buffer register, (see figure 12- 8 on page 100 and figure 12-9 on page 102 ). the pwm resolution for the phase and frequency correct pwm mode can be defined by either icr1 or ocr1a. the minimum resolution allowed is 2-bit (icr1 or ocr1a set to 0x0003), and f ocnxpcpwm f clk_i/o 2 ntop ?? --------------------------- - =
102 8006k?avr?10/10 attiny24/44/84 the maximum resolution is 16-bit (icr1 or ocr1 a set to max). the pwm resolution in bits can be calculated using the following equation: in phase and frequency correct pwm mode the counter is incremented until the counter value matches either the value in icr1 (wgm13:0 = 8), or the value in ocr1a (wgm13:0 = 9). the counter has then reac hed the top and ch anges the count di rection. the tcnt1 value will be equal to top for one timer clock cycle. the timing diagram for the phase correct and frequency correct pwm mode is shown on figure 12-9 on page 102 . the figure shows phase and fre- quency correct pwm mode when ocr1a or icr1 is used to define top. the tcnt1 value is in the timing diagram shown as a histogram for il lustrating the dual-slope operation. the diagram includes non-inverted and inverted pwm outputs. the small horizontal line marks on the tcnt1 slopes represent compare matc hes between ocr1x and tcnt1. the oc1x interrupt flag will be set when a compare match occurs. figure 12-9. phase and frequency correct pwm mode, timing diagram the timer/counter overflow flag (tov1) is set at the same timer clock cycle as the ocr1x registers are updated with the double buffer value (at bottom). when either ocr1a or icr1 is used for defining the top value, the oc1a or icf1 flag set when tcnt1 has reached top. the interrupt flags can then be used to generate an interrupt each time the counter reaches the top or bottom value. when changing the top value the program must ensure that the new top value is higher or equal to the value of all of the compare registers. if the top value is lower than any of the compare registers, a compare match will neve r occur between the tcnt1 and the ocr1x. as figure 12-9 on page 102 shows the output generated is, in contrast to the phase correct mode, symmetrical in all periods. since the ocr1x registers are updated at bottom, the length of the rising and the falling slopes wi ll always be equal. this gives symmetrical output pulses and is therefore frequency correct. r pfcpwm top 1 + () log 2 () log ---------------------------------- - = ocrnx/top upd a te a nd tovn interr u pt fl a g s et (interr u pt on bottom) ocna interr u pt fl a g s et or icfn interr u pt fl a g s et (interr u pt on top) 1 2 3 4 tcntn period ocnx ocnx (comnx1:0 = 2) (comnx1:0 = 3 )
103 8006k?avr?10/10 attiny24/44/84 using the icr1 register for defining top work s well when using fixed top values. by using icr1, the ocr1a register is free to be used for generating a pwm output on oc1a. however, if the base pwm frequency is actively changed by changing the top value, using the ocr1a as top is clearly a better choice due to its double buffer feature. in phase and frequency correct pwm mode, the compare units allow generation of pwm wave- forms on the oc1x pins. settin g the com1x1:0 bits to two will produce a non-inverted pwm and an inverted pwm output can be generated by setting the com1x1:0 to three (see table 12-4 on page 109 ). the actual oc1x value will only be visible on the port pin if the data direction for the port pin is set as output (ddr_oc1x). the pwm waveform is generated by setting (or clearing) the oc1x register at the compare match between ocr1x and tcnt1 when the counter incre- ments, and clearing (or setting) the oc1x register at compare match between ocr1x and tcnt1 when the counter decrements. the pw m frequency for the output when using phase and frequency correct pwm can be calculated by the following equation: the n variable represents the prescaler divider (1, 8, 64, 256, or 1024). the extreme values for the ocr1x register represents special cases when generating a pwm waveform output in the phase correct pwm mode. if the ocr1x is set equal to bottom the output will be continuously low and if set equal to top the output will be set to high for non- inverted pwm mode. for inverted pwm the output will have the opposite logic values. 12.9 timer/counter timing diagrams the timer/counter is a synchronous design and the timer clock (clk t1 ) is therefore shown as a clock enable signal in the following figures. the figures include information on when interrupt flags are set, and when the ocr1x register is updated with the ocr1x buffer value (only for modes utilizing double buffering). figure 12-10 shows a timing diagram for the setting of ocf1x. figure 12-10. timer/counter timing diagram, setting of ocf1x, no prescaling figure 12-11 on page 104 shows the same timing data, but with the prescaler enabled. f ocnxpfcpwm f clk_i/o 2 ntop ?? --------------------------- - = clk tn (clk i/o /1) ocfnx clk i/o ocrnx tcntn ocrnx v a l u e ocrnx - 1 ocrnx ocrnx + 1 ocrnx + 2
104 8006k?avr?10/10 attiny24/44/84 figure 12-11. timer/counter timing diagram, setting of ocf1x, with prescaler (f clk_i/o /8) figure 12-12 on page 104 shows the count sequence close to top in various modes. when using phase and frequency correct pwm mode the ocr1x register is updated at bottom. the timing diagrams will be the same, but top should be replaced by bottom, top-1 by bottom+1 and so on. the same renaming applies for modes that set the tov1 flag at bottom. figure 12-12. timer/counter timing diagram, no prescaling figure 12-13 on page 105 shows the same timing data, but with the prescaler enabled. ocfnx ocrnx tcntn ocrnx v a l u e ocrnx - 1 ocrnx ocrnx + 1 ocrnx + 2 clk i/o clk tn (clk i/o / 8 ) tovn (fpwm) a nd icfn (if us ed as top) ocrnx (upd a te a t top) tcntn (ctc a nd fpwm) tcntn (pc a nd pfc pwm) top - 1 top top - 1 top - 2 old ocrnx v a l u e new ocrnx v a l u e top - 1 top bottom bottom + 1 clk tn (clk i/o /1) clk i/o
105 8006k?avr?10/10 attiny24/44/84 figure 12-13. timer/counter timing dia gram, with prescaler (f clk_i/o /8) 12.10 accessing 16-bit registers the tcnt1, ocr1a/b, and icr1 are 16-bit registers that can be accessed by the avr cpu via the 8-bit data bus. the 16-bit register must be byte accessed using two read or write operations. each 16-bit timer has a single 8-bit register for temporary storing of the high byte of the 16-bit access. the same temporary register is shared between all 16-bit registers within each 16-bit timer. accessing the low byte triggers the 16-bit read or write operation. when the low byte of a 16-bit register is written by the cpu, the high byte stored in the temporary register, and the low byte written are both copied into the 16-bit register in the same clock cycle. when the low byte of a 16-bit register is read by the cpu, the high by te of the 16-bit register is copied into the tempo- rary register in the same clock cycle as the low byte is read. not all 16-bit accesses uses the temporary register for the high byte. reading the ocr1a/b 16- bit registers does not involve using the temporary register. to do a 16-bit write, the high byte must be written before the low byte. for a 16-bit read, the low byte must be read before the high byte. the following code examples show how to access the 16-bit timer registers assuming that no interrupts updates the temporary register. the same principle can be used directly for accessing the ocr1a/b and icr1 registers. note that when using ?c?, the compiler handles the 16-bit access. tovn (fpwm) a nd icf n (if us ed as top) ocrnx (upd a te a t top) tcntn (ctc a nd fpwm) tcntn (pc a nd pfc pwm) top - 1 top top - 1 top - 2 old ocrnx v a l u e new ocrnx v a l u e top - 1 top bottom bottom + 1 clk i/o clk tn (clk i/o / 8 )
106 8006k?avr?10/10 attiny24/44/84 note: see ?code examples? on page 6 . the assembly code example returns the tcnt1 value in the r17:r16 register pair. it is important to notice that accessing 16-bit registers are atomic operations. if an interrupt occurs between the two instructions accessing the 16-bit register, and the interrupt code updates the temporary register by accessing the same or any other of the 16-bit timer registers, then the result of the access outside the interrupt will be corrupted. therefore, when both the main code and the interrupt code update the temporary register, the main code must disable the interrupts during the 16-bit access. the following code examples show how to do an atomic read of the tcnt1 register contents. reading any of the ocr1a/b or icr1 registers can be done by using the same principle. assembly code examples ... ; set tcnt 1 to 0x01ff ldi r17,0x01 ldi r16,0xff out tcnt 1 h,r17 out tcnt 1 l,r16 ; read tcnt 1 into r17:r16 in r16,tcnt 1 l in r17,tcnt 1 h ... c code examples unsigned int i; ... /* set tcnt 1 to 0x01ff */ tcnt 1 = 0x1ff; /* read tcnt 1 into i */ i = tcnt 1 ; ... assembly code example tim16_readtcnt 1 : ; save global interrupt flag in r18,sreg ; disable interrupts cli ; read tcnt 1 into r17:r16 in r16,tcnt 1 l in r17,tcnt 1 h ; restore global interrupt flag out sreg,r18 ret
107 8006k?avr?10/10 attiny24/44/84 note: see ?code examples? on page 6 . the assembly code example returns the tcnt1 value in the r17:r16 register pair. the following code examples show how to do an atomic write of the tcnt1 register contents. writing any of the ocr1a/b or icr1 register s can be done by using the same principle. c code example unsigned int tim16_readtcnt 1 ( void ) { unsigned char sreg; unsigned int i; /* save global interrupt flag */ sreg = sreg; /* disable interrupts */ _cli(); /* read tcnt 1 into i */ i = tcnt 1 ; /* restore global interrupt flag */ sreg = sreg; return i; } assembly code example tim16_writetcnt 1 : ; save global interrupt flag in r18,sreg ; disable interrupts cli ; set tcnt 1 to r17:r16 out tcnt 1 h,r17 out tcnt 1 l,r16 ; restore global interrupt flag out sreg,r18 ret
108 8006k?avr?10/10 attiny24/44/84 note: see ?code examples? on page 6 . the assembly code example requires that the r17:r16 register pair contains the value to be writ- ten to tcnt1. 12.10.1 reusing the temporary high byte register if writing to more than one 16-bit register where the high byte is the same for all registers written, then the high byte only needs to be written once. however, note that the same rule of atomic operation described previously also applies in this case. 12.11 register description 12.11.1 tccr1a ? timer/counter1 control register a ? bits 7:6 ? com1a1, com1a0: compare output mode for channel a ? bits 5:4 ? com1b1, com1b0: compare output mode for channel b the com1a1:0 and com1b1:0 control the output compare pins (oc1a and oc1b respec- tively) behavior. if one or both of the com1a1:0 bits are written to one, the oc1a output overrides the normal port functionality of the i/o pin it is connected to. if one or both of the com1b1:0 bit are written to one, the oc1b output overrides the normal port functionality of the i/o pin it is connected to. however, note that the data direction register (ddr) bit correspond- ing to the oc1a or oc1b pin must be set in order to enable the output driver. when the oc1a or oc1b is connected to the pin, the function of the com1x1:0 bits is depen- dent of the wgm13:0 bits setting. table 12-2 on page 109 shows the com1x1:0 bit functionality when the wgm13:0 bits are set to a normal or a ctc mode (non-pwm). c code example void tim16_writetcnt 1 ( unsigned int i ) { unsigned char sreg; unsigned int i; /* save global interrupt flag */ sreg = sreg; /* disable interrupts */ _cli(); /* set tcnt 1 to i */ tcnt 1 = i; /* restore global interrupt flag */ sreg = sreg; } bit 7 6 5 4 3 2 1 0 0x2f (0x4f) com1a1 com1a0 com1b1 com1b0 ? ? wgm11 wgm10 tccr1a read/write r/w r/w r/w r/w r r r/w r/w initial value 0 0 0 0 0 0 0 0
109 8006k?avr?10/10 attiny24/44/84 table 12-3 shows the com1x1:0 bit functionality when the wgm13:0 bits are set to the fast pwm mode. note: 1. a special case occurs when ocr1a/oc r1b equals top and com1a1/com1b1 is set. in this case the compare match is ignored, but the set or clear is done at bottom. ?fast pwm mode? on page 97 for more details. table 12-4 shows the com1x1:0 bit functionality when the wgm13:0 bits are set to the phase correct or the phase and frequency correct, pwm mode. note: 1. a special case occurs when ocr1a/ ocr1b equals top and com1a1/com1b1 is set. ?phase correct pwm mode? on page 99 for more details. table 12-2. compare output mode, non-pwm com1a1/com1b1 com1a0/com1b0 description 0 0 normal port operation, oc1a/oc1b disconnected. 0 1 toggle oc1a/oc1b on compare match. 10 clear oc1a/oc1b on compare match (set output to low level). 11 set oc1a/oc1b on compare match (set output to high level). table 12-3. compare output mode, fast pwm (1) com1a1/com1b1 com1a0/com1b0 description 0 0 normal port operation, oc1a/oc1b disconnected. 01 wgm13=0: normal port operation, oc1a/oc1b disconnected. wgm13=1: toggle oc1a on compare match, oc1b reserved. 10 clear oc1a/oc1b on compare match, set oc1a/oc1b at bottom (non-inverting mode) 11 set oc1a/oc1b on compare match, clear oc1a/oc1b at bottom (inverting mode) table 12-4. compare output mode, phase correct and phase & frequency correct pwm (1) com1a1/com1b1 com1a0/com1b0 description 0 0 normal port operation, oc1a/oc1b disconnected. 01 wgm13=0: normal port operation, oc1a/oc1b disconnected. wgm13=1: toggle oc1a on compare match, oc1b reserved. 10 clear oc1a/oc1b on compare match when up- counting. set oc1a/oc1b on compare match when downcounting. 11 set oc1a/oc1b on compare match when up- counting. clear oc1a/oc1b on compare match when downcounting.
110 8006k?avr?10/10 attiny24/44/84 ? bits 1:0 ? wgm11, wgm10: waveform generation mode combined with the wgm13:2 bits found in the tccr1b register, these bits control the counting sequence of the counter, the source for maximum (top) counter value, and what type of wave- form generation to be used, see table 12-5 on page 110 . modes of operation supported by the timer/counter unit are: normal mode (counter), clear timer on compare match (ctc) mode, and three types of pulse width modulation (pwm) modes. ( ?modes of operation? on page 96 ). 12.11.2 tccr1b ? timer/counter1 control register b ? bit 7 ? icnc1: input capture noise canceler setting this bit (to one) activates the input capt ure noise canceler. when the noise canceler is activated, the input from the input capture pin (icp1) is filtered. the filter function requires four successive equal valued samples of the icp1 pin for changing its output. the input capture is therefore delayed by four oscillator cycles when the noise canceler is enabled. ? bit 6 ? ices1: input capture edge select this bit selects which edge on the input capture pin (icp1) that is used to trigger a capture event. when the ices1 bit is written to zero, a falling (negative) edge is used as trigger, and when the ices1 bit is written to one, a risi ng (positive) edge w ill trigger the capture. table 12-5. waveform generation modes mode wgm 13:10 mode of operation top update of ocr1 x at tov1 flag set on 0 0000 normal 0xffff immediate max 1 0001 pwm, phase correct, 8-bit 0x00ff top bottom 2 0010 pwm, phase correct, 9-bit 0x01ff top bottom 3 0011 pwm, phase correct, 10-bit 0x03ff top bottom 40100ctc ( clear timer on compare ) ocr1a immediate max 5 0101 fast pwm, 8-bit 0x00ff top top 6 0110 fast pwm, 9-bit 0x01ff top top 7 0111 fast pwm, 10-bit 0x03ff top top 8 1000 pwm, phase & freq. correct icr1 bottom bottom 9 1001 pwm, phase & freq. correct ocr1a bottom bottom 10 1010 pwm, phase correct icr1 top bottom 11 1011 pwm, phase correct ocr1a top bottom 12 1100 ctc ( clear timer on compare ) icr1 immediate max 13 1101 (reserved) ? ? ? 14 1110 fast pwm icr1 top top 15 1111 fast pwm ocr1a top top bit 7654 3210 0x2e (0x4e) icnc1 ices1 ? wgm13 wgm12 cs12 cs11 cs10 tccr1b read/write r/w r/w r r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
111 8006k?avr?10/10 attiny24/44/84 when a capture is triggered according to the ices1 setting, the counter value is copied into the input capture register (icr1). the event will also set the input capture flag (icf1), and this can be used to cause an input capture interrupt, if this interrupt is enabled. when the icr1 is used as top value (see description of the wgm13:0 bits located in the tccr1a and the tccr1b register), the icp1 is disconnected and consequently the input cap- ture function is disabled. ? bit 5 ? res: reserved bit this bit is reserved for future use. for ensuring compatibility with future de vices, this bit must be written to zero when tccr1b is written. ? bits 4:3 ? wgm13, wgm12: waveform generation mode see tccr1a register description. ? bits 2:0 ? cs12, cs11, cs10: clock select the three clock select bits select the clock source to be used by the timer/counter, see figure 12-10 and figure 12-11 . if external pin modes are used for the timer/counter1, transitions on the t1 pin will clock the counter even if the pin is configured as an output. this feature allows software control of the counting. 12.11.3 tccr1c ? timer/counter1 control register c ? bit 7 ? foc1a: force output compare for channel a ? bit 6 ? foc1b: force output compare for channel b the foc1a/foc1b bits are only active when the wgm13:0 bits specifies a non-pwm mode. however, for ensuring compatibility with future devices, these bits must be set to zero when tccr1a is written when operating in a pwm mode. when writing a logical one to the foc1a/foc1b bit, an immediate compare match is forced on the waveform generation unit. the oc1a/oc1b output is changed according to its com1x1:0 bits setting. note that the table 12-6. clock select bit description cs12 cs11 cs10 description 0 0 0 no clock source (timer/counter stopped). 001clk i/o /1 (no prescaling) 010clk i/o /8 (from prescaler) 011clk i/o /64 (from prescaler) 100clk i/o /256 (from prescaler) 101clk i/o /1024 (from prescaler) 1 1 0 external clock source on t1 pin. clock on falling edge. 1 1 1 external clock source on t1 pin. clock on rising edge. bit 7654 3210 0x22 (0x42) foc1a foc1b ? ? ? ? ? ? tccr1c read/write w w r r r r r r initial value 0 0 0 0 0 0 0 0
112 8006k?avr?10/10 attiny24/44/84 foc1a/foc1b bits are implemented as strobes. therefore it is the value present in the com1x1:0 bits that determine the effect of the forced compare. a foc1a/foc1b strobe will not generate any interrupt nor will it clear the timer in clear timer on compare match (ctc) mode using ocr1a as top. the foc1a/foc1b bits are always read as zero. ? bits 5:0 ? res: reserved bits this bit is reserved for future use. for ensuring compatibility with future de vices, this bit must be written to zero when the register is written. 12.11.4 tcnt1h and tcnt1l ? timer/counter1 the two timer/counter i/o locations (tcnt1 h and tcnt1l, combined tcnt1) give direct access, both for read and for write operations, to the timer/counter unit 16-bit counter. to ensure that both the high and low bytes are read and written simultaneously when the cpu accesses these registers, the access is perfo rmed using an 8-bit temporary high byte register (temp). this temporary register is shared by all the other 16-bit registers. see ?accessing 16-bit registers? on page 105 . modifying the counter (tcnt1) while the counte r is running introduces a risk of missing a com- pare match between tcnt1 and one of the ocr1x registers. writing to the tcnt1 register blocks (removes) the compare match on the following timer clock for all compare units. 12.11.5 ocr1ah and ocr1al ? ou tput compare register 1 a 12.11.6 ocr1bh and ocr1bl ? ou tput compare register 1 b the output compare registers contain a 16-bit value that is continuously compared with the counter value (tcnt1). a match can be used to generate an output compare interrupt, or to generate a waveform output on the oc1x pin. the output compare registers are 16-bit in size. to ensure that both the high and low bytes are written simultaneously when the cp u writes to these registers, the access is performed using an 8-bit temporary high byte register (temp). this temporary register is shared by all the other 16- bit registers. see ?accessing 16-bit registers? on page 105 . bit 76543210 0x2d (0x4d) tcnt1[15:8] tcnt1h 0x2c (0x4c) tcnt1[7:0] tcnt1l read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x2b (0x4b) ocr1a[15:8] ocr1ah 0x2a (0x4a) ocr1a[7:0] ocr1al read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 0x29 (0x49) ocr1b[15:8] ocr1bh 0x28 (0x48) ocr1b[7:0] ocr1bl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
113 8006k?avr?10/10 attiny24/44/84 12.11.7 icr1h and icr1l ? input capture register 1 the input capture is updated with the counter (tcnt1) value each time an event occurs on the icp1 pin (or optionally on the analog comparator output for timer/counter1). the input capture can be used for defining the counter top value. the input capture register is 16-bit in size. to ensure that both the high and low bytes are read simultaneously when the cpu accesses these regi sters, the access is performed using an 8-bit temporary high byte register (temp). this temporary register is shared by all the other 16-bit registers. ?accessing 16-bit registers? on page 105 . 12.11.8 timsk1 ? timer/counter interrupt mask register 1 ? bits 7:6 ? res: reserved bits these bits are reserved in the attiny 24/44/84 and will always read as zero. ? bit 5 ? icie1: timer/counter1, input capture interrupt enable when this bit is written to one, and the i-flag in the status register is set (interrupts globally enabled), the timer/countern input capture interrupt is enabled. the corresponding interrupt vector (see ?interrupts? on page 66.) is executed when the icf1 flag, located in tifr1, is set. ? bits 4:3 ? res: reserved bits these bits are reserved in the attiny 24/44/84 and will always read as zero. ? bit 2 ? ocie1b: timer/counter1, output compare b match interrupt enable when this bit is written to one, and the i-flag in the status register is set (interrupts globally enabled), the timer/counter1 output compare b match interrupt is enabled. the corresponding interrupt vector (see ?interrupts? on page 48 ) is executed when the ocf1b flag, located in tifr1, is set. ? bit 1 ? ocie1a: timer/counter1, output compare a match interrupt enable when this bit is written to one, and the i-flag in the status register is set (interrupts globally enabled), the timer/counter1 output compare a match interrupt is enabled. the corresponding interrupt vector (see ?interrupts? on page 48 ) is executed when the ocf1a flag, located in tifr1, is set. ? bit 0 ? toie1: timer/counter1, overflow interrupt enable when this bit is written to one, and the i-flag in the status register is set (interrupts globally enabled), the timer/counter1 overflow interrupt is enabled. the corresponding interrupt vector (see ?interrupts? on page 48 ) is executed when the tov1 flag, located in tifr1, is set. bit 76543210 0x25 (0x45) icr1[15:8] icr1h 0x24 (0x44) icr1[7:0] icr1l read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 7 6 5 4 3 2 1 0 0x0c (0x2c) ? ? icie1 ? ? ocie1b ocie1a toie1 timsk1 read/write r r r/w r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0
114 8006k?avr?10/10 attiny24/44/84 12.11.9 tifr1 ? timer/counter interrupt flag register 1 ? bits 7:6 ? res: reserved bits these bits are reserved in the attiny 24/44/84 and will always read as zero. ? bit 5 ? icf1: timer/count er1, input capture flag this flag is set when a capture event occurs on the icp1 pin. when the input capture register (icr1) is set by the wgm13:0 to be used as the top value, the icf1 flag is set when the coun- ter reaches the top value. icf1 is automatically cleared when the input capt ure interrupt vector is executed. alternatively, icf1 can be cleared by writing a logic one to its bit location. ? bits 4:3 ? res: reserved bits these bits are reserved in the attiny 24/44/84 and will always read as zero. ? bit 2 ? ocf1b: timer/counter1, output compare b match flag this flag is set in the timer clock cycle afte r the counter (tcnt1) value matches the output compare register b (ocr1b). note that a forced output compare (1 b) strobe will not set the ocf1b flag. ocf1b is automatically cleared when the output compare match b interrupt vector is exe- cuted. alternatively, ocf1b can be cleared by writing a logic one to its bit location. ? bit 1 ? ocf1a: timer/counter1, output compare a match flag this flag is set in the timer clock cycle afte r the counter (tcnt1) value matches the output compare register a (ocr1a). note that a forced output compare (1 a) strobe will not set the ocf1a flag. ocf1a is automatically cleared when the output compare match a interrupt vector is exe- cuted. alternatively, ocf1a can be cleared by writing a logic one to its bit location. ? bit 0 ? tov1: timer/counter1, overflow flag the setting of this flag is dependent of the wgm13:0 bits setting. in normal and ctc modes, the tov1 flag is set when the timer overflows. see table 12-5 on page 110 for the tov1 flag behavior when using another wgm13:0 bit setting. tov1 is automatically cleared when the timer/c ounter1 overflow interrupt vector is executed. alternatively, tov1 can be cleared by writing a logic one to its bit location. bit 765432 1 0 0x0b (0x2b) ? ? icf1 ? ? ocf1b ocf1a tov1 tifr1 read/write r r r/w r r r/w r/w r/w initial value000000 0 0
115 8006k?avr?10/10 attiny24/44/84 13. timer/counter prescaler timer/counter0 and timer/counter1 share the same prescaler module, but the timer/counters can have different prescaler settings. the description below applies to both timer/counters. tn is used as a general name, n = 0, 1. the timer/counter can be clocked directly by the system clock (by setting the csn2:0 = 1). this provides the fastest operation, with a maximum timer/counter clock frequency equal to system clock frequency (f clk_i/o ). alternatively, one of four taps from the prescaler can be used as a clock source. the prescaled clock has a frequency of either f clk_i/o /8, f clk_i/o /64, f clk_i/o /256, or f clk_i/o /1024. 13.1 prescaler reset the prescaler is free running, i.e., operates independently of the clock select logic of the timer/countercounter, and it is shared by the timer/counter tn. since the prescaler is not affected by the timer/counter?s cl ock select, the state of the pres caler will have implications for situations where a prescaled clock is used. one example of prescaling artifacts occurs when the timer is enabled and clocked by the prescaler (csn2:0 = 2, 3, 4, or 5). the number of system clock cycles from when the timer is enabled to the first count occurs can be from 1 to n+1 sys- tem clock cycles, where n equals the prescaler divisor (8, 64, 256, or 1024). the prescaler reset can be used for synchronizing the timer/counter to program execution. 13.2 external clock source an external clock source applied to the tn pin can be used as timer/counter clock (clk tn ). the tn pin is sampled once every system clock cycle by the pin synchronization logic. the synchro- nized (sampled) signal is then passed through the edge detector. figure 13-1 shows a functional equivalent block diagram of the tn synchroniza tion and edge detector logic. the registers are clocked at the positive edge of the internal system clock ( clk i/o ). the latch is transparent in the high period of the internal system clock. figure 13-1. t0 pin sampling the edge detector generates one clk t 0 pulse for each positive (csn2:0 = 7) or negative (csn2:0 = 6) edge it detects. the synchronization and edge detector logic introduces a delay of 2.5 to 3.5 system clock cycles from an edge has been applied to the tn pin to the counter is updated. enabling and disabling of the clock input must be done when tn has been stable for at least one system clock cycle, otherwise it is a risk that a false timer/counter clock pulse is generated. each half period of the external clock applie d must be longer than one system clock cycle to ensure correct sampling. the external clock must be guaranteed to have less than half the sys- tem clock frequency (f extclk < f clk_i/o /2) given a 50/50% duty cycle. since the edge detector uses sampling, the maximum frequency of an external clock it can detect is half the sampling fre- tn_ s ync (to clock select logic) edge detector synchronization dq dq le dq tn clk i/o
116 8006k?avr?10/10 attiny24/44/84 quency (nyquist sampling theorem). however, due to variation of the system clock frequency and duty cycle caused by oscillator source (crystal, resonator, and capacitors) tolerances, it is recommended that maximum frequency of an external clock source is less than f clk_i/o /2.5. an external clock source can not be prescaled. figure 13-2. prescaler for timer/counter0 note: 1. the synchronization logic on the input pins ( t0) is shown in figure 13-1 on page 115 . 13.3 register description 13.3.1 gtccr ? general timer/counter control register ? bit 7 ? tsm: timer/counter synchronization mode writing the tsm bit to one activates the timer/counter synchronization mode. in this mode, the value that is written to the psr10 bit is kept, hence keeping the prescaler reset signal asserted. this ensures that the timer/counter is halted and can be configured without the risk of advanc- ing during configuration. when the tsm bit is written to zero, the psr10 bit is cleared by hardware, and the timer/counter start counting. ? bit 0 ? psr10: prescaler 0 reset timer/counter n when this bit is one, the timer/countern prescale r will be reset. this bit is normally cleared immediately by hardware, except if the tsm bit is set. psr10 clear clk t0 t0 clk i/o synchronization bit 7 6 5 4 3 2 1 0 0x23 (0x43) tsm ? ? ? ? ? ? psr10 gtccr read/write r/w r r r r r r r/w initial value 0 0 0 0 0 0 0 0
117 8006k?avr?10/10 attiny24/44/84 14. usi ? universal serial interface 14.1 features ? two-wire synchronous data tr ansfer (master or slave) ? three-wire synchronous data transfer (master or slave) ? data received interrupt ? wakeup from idle mode ? in two-wire mode: wake-up from all sleep modes, including power-down mode ? two-wire start condition detect or with interr upt capability 14.2 overview the universal serial interface (usi), provides the basic hardware resources needed for serial communication. combined with a minimum of cont rol software, the usi allows significantly higher transfer rates and uses less code space than solutions based on software only. interrupts are included to minimize the processor load. a simplified block diagram of the usi is shown in figure 14-1 for actual placement of i/o pins refer to ?pinout attiny24/44/84? on page 2 . device-specific i/o register and bit locations are listed in the ?register descriptions? on page 124 . figure 14-1. universal serial interface, block diagram the 8-bit usi data register (usidr) contains the incoming and outgoing data. it is directly accessible via the data bus but a copy of the c ontents is also placed in the usi buffer register (usibr) where it can be retrieved later. if reading the usi data register directly, the register must be read as quickly as possible to ensure that no data is lost. the most significant bit of the usi data register is connected to one of two output pins (depend- ing on the mode configuration, see ?usicr ? usi control register? on page 126 ). there is a transparent latch between the output of the usi data register and the output pin, which delays data bus usipf usitc usiclk usics0 usics1 usioif usioie usidc usisif usiwm0 usiwm1 usisie bit7 two-wire clock control unit do (output only) di/sda (input/open drain) usck/scl (input/open drain) 4-bit counter usidr usisr dq le usicr clock hold tim0 comp bit0 [1] 3 0 1 2 3 0 1 2 0 1 2 usidb
118 8006k?avr?10/10 attiny24/44/84 the change of data output to the opposite clock edge of the data input sampling. the serial input is always sampled from the data input (di) pin independent of the configuration. the 4-bit counter can be both read and written via the data bus, and it can generate an overflow interrupt. both the usi data register and the counter are clocked simultaneously by the same clock source. this allows the counter to count the number of bits received or transmitted and generate an interrupt when the transfer is complete. note that when an external clock source is selected the counter counts both clock edges. this means the counter registers the number of clock edges and not the number of data bits. the clock can be selected from three different sources: the usck pin, timer/counter0 compare match or from software. the two-wire clock control unit can be configured to generate an interrupt when a start condition has been detected on the two-wire bus. it can also be set to generate wait states by holding the clock pin low after a start condition is detected, or after the counter overflows. 14.3 functional descriptions 14.3.1 three-wire mode the usi three-wire mode is compliant to the serial peripheral interface (spi) mode 0 and 1, but does not have the slave select (ss) pin functionality. however, this feature can be implemented in software if necessary. pin names used by this mode are: di, do, and usck. figure 14-2. three-wire mode operat ion, simplified diagram figure 14-2 shows two usi units operating in three-wire mode, one as master and one as slave. the two usi data registers are interconnected in such way that after eight usck clocks, the data in each register has been interchanged. the same clock also increments the usi?s 4-bit counter. the counter overflow (interrupt) flag, or usioif, can therefore be used to determine when a transfer is completed. the clock is generated by the master device software by toggling the usck pin via the porta register or by writing a one to bit usitc bit in usicr. slave master bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 do di usck bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 do di usck portxn
119 8006k?avr?10/10 attiny24/44/84 figure 14-3. three-wire mode, timing diagram the three-wire mode timing is shown in figure 14-3 at the top of the figure is a usck cycle ref- erence. one bit is shifted into the usi data register (usidr) for eac h of these cycles. the usck timing is shown for both external clock modes. in external clock mode 0 (usics0 = 0), di is sampled at positive edges, and do is changed (u si data register is shifted by one) at nega- tive edges. in external clock mode 1 (usics0 = 1) the opposite edges with respect to mode 0 are used. in other words, data is sampled at negative and output is changed at positive edges. the usi clock modes corresponds to the spi data mode 0 and 1. referring to the timing diagram ( figure 14-3 ), a bus transfer involves the following steps: 1. the slave and master devices set up their data outputs and, depending on the protocol used, enable their output drivers (mark a and b). the output is set up by writing the data to be transmitted to the usi data regi ster. the output is enabled by setting the corresponding bit in the data direction register of port a. note that there is not a pre- ferred order of points a and b in the figure, but both must be at least one half usck cycle before point c, where the data is sampled. this is in order to ensure that the data setup requirement is satisfied. the 4-bit counter is reset to zero. 2. the master software generates a clock puls e by toggling the usck line twice (c and d). the bit values on the data input (di) pins are sampled by the usi on the first edge (c), and the data output is changed on the opposite edge (d). the 4-bit counter will count both edges. 3. step 2. is repeated eight times for a complete register (byte) transfer. 4. after eight clock pulses (i.e ., 16 clock edges) the counter w ill overflow and indicate that the transfer has been completed. if usi buffer registers are not used the data bytes that have been transferred must now be processed before a new transfer can be initi- ated. the overflow interrupt will wake up the processor if it is set to idle mode. depending on the protocol used the slav e device can now set its output to high impedance. 14.3.2 spi master operation example the following code demonstrates how to use the usi module as a spi master: spitransfer: out usidr,r16 ldi r16,(1< 120 8006k?avr?10/10 attiny24/44/84 spitransfer_loop: out usicr,r17 in r16, usisr sbrs r16, usioif rjmp spitransfer_loop in r16,usidr ret the code is size optimized using only eight in structions (plus return). the code example assumes that the do and usck pins have been enabled as outputs in ddra. the value stored in register r16 prior to the function is called is transferred to the slave device, and when the transfer is completed the data received from the slave is stored back into the register r16. the second and third instructions clear the usi counter overflow flag and the usi counter value. the fourth and fifth instructions set three-wire mode, positive edge clock, count at usitc strobe, and toggle usck. the loop is repeated 16 times. the following code demonstrates how to use the usi as an spi master with maximum speed (f sck = f ck /2): spitransfer_fast: out usidr,r16 ldi r16,(1< 121 8006k?avr?10/10 attiny24/44/84 14.3.3 spi slave operation example the following code demonstrates how to use the usi module as a spi slave: init: ldi r16,(1< 122 8006k?avr?10/10 attiny24/44/84 figure 14-4. two-wire mode operation, simplified diagram the data direction is not given by the physical layer. a protocol, like the one used by the twi- bus, must be implemented to control the data flow. figure 14-5. two-wire mode, typical timing diagram referring to the timing diagram ( figure 14-5 ), a bus transfer involves the following steps: 1. the start condition is generated by the master by forcing the sda low line while keep- ing the scl line high (a). sda can be forced low either by writing a zero to bit 7 of the usi data register, or by setting the corresponding bit in the porta register to zero. note that the data direction register bit must be set to one for the output to be enabled. the start detector logic of the slave device (see figure 14-6 on page 123 ) detects the start condition and sets the usisif flag. the flag can generate an interrupt if necessary. 2. in addition, the start detector will hold the scl line low after the master has forced a negative edge on this line (b). this allows the slave to wake up from sleep or complete other tasks before setting up the usi data register to receive the address. this is done by clearing the start condition flag and resetting the counter. master slave bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sda scl bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 two-wire clock control unit hold scl portxn sda scl vcc p s address 1 - 7 8 9 r/w ack ack 1 - 8 9 data ack 1 - 8 9 data sda scl a b d e c f
123 8006k?avr?10/10 attiny24/44/84 3. the master set the first bit to be transferred and releases the scl line (c). the slave samples the data and shifts it into the usi data register at the positive edge of the scl clock. 4. after eight bits containing slave address and data direction (read or write) have been transferred, the slave counter overflows and the scl line is forced low (d). if the slave is not the one the master has addressed, it releases the scl line and waits for a new start condition. 5. when the slave is addressed, it holds the sda line low during the acknowledgment cycle before holding the scl line low again (i.e., the usi counter register must be set to 14 before releasing scl at (d)). depending on the r/w bit the master or slave enables its output. if the bit is set, a master read operation is in progress (i.e., the slave drives the sda line) the slave can hold the scl line low after the acknowledge (e). 6. multiple bytes can now be transmitted, all in same direction, until a stop condition is given by the master (f), or a new start condition is given. if the slave is not able to receive more data it does not acknowledge the data byte it has last received. when the master does a read operation it must terminate the operation by forcing the acknowledge bit low after the last byte transmitted. 14.3.5 start condition detector the start condition detector is shown in figure 14-6 . the sda line is delayed (in the range of 50 to 300 ns) to ensure valid sampling of the scl line. the start condition detector is only enabled in two-wire mode. figure 14-6. start condition detector, logic diagram the start condition detector works asynchronous ly and can therefore wake up the processor from power-down sleep mode. however, the protocol used might have restrictions on the scl hold time. therefore, w hen using this feature the oscillator st art-up time (set by cksel fuses, see ?clock sources? on page 25 ) must also be taken into consideration. refer to the description of the usisif bit on page 125 for further details. 14.3.6 clock speed considerations maximum frequency for scl and sck is f ck / 2. this is also the maximum data transmit and receive rate in both two- and three-wire mode . in two-wire slave mode the two-wire clock con- trol unit will hold the scl low unt il the slave is ready to receive more data. this may reduce the actual data rate in two-wire mode. sda scl write( usisif) clock hold usisif dq clr dq clr
124 8006k?avr?10/10 attiny24/44/84 14.4 alternative usi usage the flexible design of the usi allows it to be used for other tasks when serial communication is not needed. below are some examples. 14.4.1 half-duplex asynchronous data transfer using the usi data register in three-wire mode it is possible to implement a more compact and higher performance uart than by software, only. 14.4.2 4-bit counter the 4-bit counter can be used as a stand-alone counter with overflow interrupt. note that if the counter is clocked externally, both cl ock edges will increment the counter value. 14.4.3 12-bit timer/counter combining the 4-bit usi counter with one of the 8-bit timer/counters creates a 12-bit counter. 14.4.4 edge triggered external interrupt by setting the counter to maximum value (f) it can function as an additional external interrupt. the overflow flag and interrupt enable bit are th en used for the external interrupt. this feature is selected by the usics1 bit. 14.4.5 software interrupt the counter overflow interrupt can be used as a software interrupt triggered by a clock strobe. 14.5 register descriptions 14.5.1 usidr ? usi data register the usi data register can be accessed directly but a copy of the data can also be found in the usi buffer register. depending on the usics1:0 bits of the usi control register a (left) shift operation may be per- formed. the shift operation can be synchronised to an external clock edge, to a timer/counter0 compare match, or directly to software via the usiclk bit. if a serial clock occurs at the same cycle the register is written, the register will c ontain the value written a nd no shift is performed. note that even when no wire mode is selected (usiwm1:0 = 0) both the external data input (di/sda) and the external clock input (usck/scl) can still be used by the usi data register. the output pin (do or sda, depending on the wire mode) is connected via the output latch to the most significant bit (bit 7) of the usi data register. the output latch ensures that data input is sampled and data output is changed on opposite clock edges. the latch is open (transparent) during the first half of a serial clock cycle when an external clock source is selected (usics1 = 1) and constantly open when an internal clock s ource is used (usics1 = 0). the output will be changed immediately when a new msb is written as long as the latch is open. note that the data direction register bit corresponding to the output pin must be set to one in order to enable data output from the usi data register. bit 7 6 5 4 3 2 1 0 0x0f (0x2f) msb lsb usidr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
125 8006k?avr?10/10 attiny24/44/84 14.5.2 usibr ? usi data buffer instead of reading data from the usi data regi ster the usi buffer register can be used. this makes controlling the usi less time critical and gives the cpu more time to handle other pro- gram tasks. usi flags as set similarly as when reading the usidr register. the content of the usi data register is loaded to the usi buffer register when the transfer has been completed. 14.5.3 usisr ? usi status register the status register contains interrupt flags, line status flags and the counter value. ? bit 7 ? usisif: start condition interrupt flag when two-wire mode is selected, the usisif flag is set (to one) when a start condition has been detected. when three-wire mode or output disable mode has been selected any edge on the sck pin will set the flag. if usisie bit in usicr and the global interrupt enable flag are set, an interrupt will be gener- ated when this flag is set. the flag will only be cl eared by writing a logical one to the usisif bit. clearing this bit will release the start detec tion hold of uscl in two-wire mode. a start condition interr upt will wakeup the processor from all sleep modes. ? bit 6 ? usioif: counter overflow interrupt flag this flag is set (one) when the 4-bit counter overfl ows (i.e., at the transition from 15 to 0). if the usioie bit in usicr and the glob al interrupt enable flag are se t an interrupt will also be gener- ated when the flag is set. the flag will only be cleared if a one is wr itten to the usioif bit. clearing this bit will release the counter overfl ow hold of scl in two-wire mode. a counter overflow interrup t will wakeup the processor from idle sleep mode. ? bit 5 ? usipf: stop condition flag when two-wire mode is selected, the usipf flag is set (one) when a stop condition has been detected. the flag is cleared by writing a one to this bit. note that this is not an interrupt flag. this signal is useful when implementing two-wire bus master arbitration. ? bit 4 ? usidc: data output collision this bit is logical one when bit 7 in the usi data register differs from the physical pin value. the flag is only valid when two-wire mode is used. th is signal is useful when implementing two-wire bus master arbitration. ? bits 3:0 ? usicnt3:0: counter value these bits reflect the current 4-bit counter value. the 4-bit counter value can directly be read or written by the cpu. bit 7 6 5 4 3 2 1 0 0x10 (0x30) msb lsb usibr read/write r r r r r r r r initial value 0 0 0 0 0 0 0 0 bit 7 6 5 4 3 2 1 0 0x0d (0x2d) usisif usioif usipf usidc usi cnt3 usicnt2 usicnt 1 usicnt0 usisr read/write r/w r/w r/w r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
126 8006k?avr?10/10 attiny24/44/84 the 4-bit counter increments by one for each clock generated either by the external clock edge detector, by a timer/counter0 compare match, or by software using usiclk or usitc strobe bits. the clock source depends on the setting of the usics1:0 bits. for external clock operation a special feature is added that allows the clock to be generated by writing to the usitc strobe bit. this feature is enabled by choosing an external clock source (usics1 = 1) and writing a one to the usiclk bit. note that even when no wire mode is selected (usiwm1:0 = 0) the external clock input (usck/scl) can still be used by the counter. 14.5.4 usicr ? usi control register the usi control register includes bits for interru pt enable, setting the wire mode, selecting the clock and clock strobe. ? bit 7 ? usisie: start condition interrupt enable setting this bit to one enables the start condition detector interrupt. if there is a pending interrupt and usisie and the global interrupt enable flag are set to one the interrupt will be executed immediately. refer to the usisif bit description on page 125 for further details. ? bit 6 ? usioie: counter overflow interrupt enable setting this bit to one enables the counter overflow interrupt. if there is a pending interrupt and usioie and the global interrup t enable flag are set to one th e interrupt will be executed imme- diately. refer to the usioif bit description on page 125 for further details. ? bits 5:4 ? usiwm1, usiwm0: wire mode these bits set the type of wire mode to be used, as shown in table 14-1 on page 127 . basically, only the function of the outputs are affected by these bits. data and clock inputs are not affected by t he mode selected and will always have th e same function. the counter and usi data register can therefore be clocked externally and data input sampled, even when outputs are disabled. bit 7 6 5 4 3 2 1 0 0x0d (0x2d) usisie usioie usiwm1 usiwm0 usics1 usics0 usiclk usitc usicr read/write r/w r/w r/w r/w r/w r/w w w initial value 0 0 0 0 0 0 0 0
127 8006k?avr?10/10 attiny24/44/84 note: 1. the di and usck pins are renamed to serial data (sda) and serial clock (scl) respectively to avoid confusion between the modes of operation. ? bits 3:2 ? usics1, usics0: clock source select these bits set the clock source for the usi data register and counter. the data output latch ensures that the output is changed at the opposite edge of the sampling of the data input (di/sda) when using external clock source (usck/scl). when software strobe or timer/counter0 compare match clock option is selected, the output latch is transparent and therefore the output is changed immediately. clearing the usics1:0 bits enables software strobe option. when using this option, writing a one to the usiclk bit clocks both the usi data register and the counter. for external clock source (usics1 = 1), the usiclk bit is no longer used as a strobe, but selects between external clocking and software clocking by the usitc strobe bit. table 14-1. relationship between usiw m1:0 and usi operation usiwm1 usiwm0 description 00 outputs, clock hold, and start detector disabled. port pins operate as normal. 01 three-wire mode. uses do, di, and usck pins. the data output (do) pin overrides the corresponding bit in the porta register. however, the corresponding ddra bit still controls the data direction. when the port pin is set as input the pi n pull-up is controlled by the porta bit. the data input (di) and serial clock (usck) pins do not affect the normal port operation. when operating as master, clock pulses are software generated by toggling the porta register, while the da ta direction is set to output. the usitc bit in the usicr register can be used for this purpose. 10 two-wire mode. uses sda (di) and scl (usck) pins (1) . the serial data (sda) and the serial clock (scl) pins are bi-directional and use open-collector output drives. the out put drivers are enabled by setting the corresponding bit for sda and scl in the ddra register. when the output driver is enabled for the sda pin, the output driver will force the line sda low if the output of the usi data register or the corresponding bit in the porta register is zero. otherwise, the sda line will not be driven (i.e., it is released). when the scl pin output driver is enabled the scl line will be forced low if the corresponding bit in the porta register is zero, or by the start detector. otherwise the scl line will not be driven. the scl line is held low when a start de tector detects a start condition and the output is enabled. clearing the start c ondition flag (usisif) releases the line. the sda and scl pin inputs is not affected by enabling this mode. pull-ups on the sda and scl port pin are disabled in two-wire mode. 11 two-wire mode. uses sda and scl pins. same operation as in two-wire mode abo ve, except that the scl line is also held low when a counter overflow occurs, and until the counter overflow flag (usioif) is cleared.
128 8006k?avr?10/10 attiny24/44/84 table 14-2 shows the relationship between the usics1:0 and usiclk setting and clock source used for the usi data register and the 4-bit counter. ? bit 1 ? usiclk: clock strobe writing a one to this bit location strobes the usi data register to shift one step and the counter to increment by one, provided that the software clock strobe option has been selected by writing usics1:0 bits to zero. the output will change immediately when the clock strobe is executed, i.e., during the same instruction cycle. the value shifted into the usi data register is sampled the previous instruction cycle. when an external clock source is selected (usics1 = 1), the usiclk function is changed from a clock strobe to a clock select register. setting the usiclk bit in this case will select the usitc strobe bit as clock sour ce for the 4-bit counter (see table 14-2 ). the bit will be read as zero. ? bit 0 ? usitc: toggle clock port pin writing a one to this bit location toggles the usck/s cl value either from 0 to 1, or from 1 to 0. the toggling is independent of the setting in the data direction register, but if the port value is to be shown on the pin the corresponding ddr pin must be set as output (to one). this feature allows easy clock generation when implementing master devices. when an external clock source is selected (usics 1 = 1) and the usiclk bit is set to one, writ- ing to the usitc strobe bit will directly clock th e 4-bit counter. this allows an early detection of when the transfer is done when operating as a master device. the bit will read as zero. table 14-2. relationship between the usics1:0 and usiclk setting usics1 usics0 usiclk clock sour ce 4-bit counter clock source 0 0 0 no clock no clock 0 0 1 software clock strobe (usiclk) software clock strobe (usiclk) 0 1 x timer/counter0 compare matc h timer/counter0 compare match 1 0 0 external, positive edge external, both edges 1 1 0 external, negative edge external, both edges 1 0 1 external, positive edge software clock strobe (usitc) 1 1 1 external, negative edge software clock strobe (usitc)
129 8006k?avr?10/10 attiny24/44/84 15. analog comparator the analog comparator compares the input values on the positive pin ain0 and negative pin ain1. when the voltage on the positive pin ain0 is higher than the voltage on the negative pin ain1, the analog comparator output, aco, is set. the comparator can trigger a separate inter- rupt, exclusive to the analog comparator. the user can select interrupt triggering on comparator output rise, fall or toggle. a block diagram of t he comparator and its surrounding logic is shown in figure 15-1 . figure 15-1. analog comparator block diagram notes: 1. see table 15-1 on page 129 . see figure 1-1 on page 2 and table 10-9 on page 67 for analog comparator pin placement. 15.1 analog comparator multiplexed input when the analog to digital converter (adc) is configurated as single ended input channel, it is possible to select any of the adc7:0 pins to replace the negative input to the analog compara- tor. the adc multiplexer is used to select this input, and consequently, the adc must be switched off to utilize this feature. if the analog comparator multiplexer enable bit (acme in adcsrb) is set and the adc is switched off (ade n in adcsra is zero), mux1:0 in admux select the input pin to replace the negative input to the analog comparator, as shown in table 15-1 . if acme is cleared or aden is set, ain1 is applied to the negative input to the analog comparator. acbg bandgap reference adc multiplexer output acme aden (1) acic to t/c1 c a pt u re trigger mux table 15-1. analog comparator multiplexed input acme aden mux4:0 analog comparator negative input 0 x xxxxx ain1 1 1 xxxxx ain1 1 0 00000 adc0 1 0 00001 adc1 1 0 00010 adc2 1 0 00011 adc3
130 8006k?avr?10/10 attiny24/44/84 15.2 register description 15.2.1 acsr ? analog comparator control and status register ? bit 7 ? acd: analog comparator disable when this bit is written logic one , the power to the analog comparator is switched off. this bit can be set at any time to tu rn off the analog com parator. this will reduce power consumption in active and idle mode. when changing the acd bit, the analog comparator interrupt must be disabled by clearing the acie bit in acsr. otherwise an interrupt can occur when the bit is changed. ? bit 6 ? acbg: analog comparator bandgap select when this bit is set, a fixed, internal bandgap reference voltage replaces the positive input to the analog comparator. when this bit is cleared, ain0 is applied to the positive input of the analog comparator. ? bit 5 ? aco: analog comparator output the output of the analog comparator is synchronized and then directly connected to aco. the synchronization introduces a delay of 1 - 2 clock cycles. ? bit 4 ? aci: analog comparator interrupt flag this bit is set by hardware when a comparator output event triggers the interrupt mode defined by acis1 and acis0. the analog comparator interr upt routine is executed if the acie bit is set and the i-bit in sreg is set. aci is cleared by hardware when executing the corresponding inter- rupt handling vector. alternatively, aci is cleared by writing a logic one to the flag. ? bit 3 ? acie: analog comparator interrupt enable when the acie bit is written logic one and the i-bi t in the status register is set, the analog com- parator interrupt is activated. when written logic zero, the interrupt is disabled. ? bit 2 ? acic: analog comparator input capture enable when written logic one, this bit enables the input capture function in timer/counter1 to be trig- gered by the analog comparator. the comparator output is in this case directly connected to the input capture front-end logic, making the compar ator utilize the noise canceler and edge select features of the timer/counter1 input capture interrupt. when written logic zero, no connection 1 0 00100 adc4 1 0 00101 adc5 1 0 00110 adc6 1 0 00111 adc7 table 15-1. analog comparator multiplexed input (continued) acme aden mux4:0 analog comparator negative input bit 76543210 0x08 (0x28) acd acbg aco aci acie acic acis1 acis0 acsr read/write r/w r/w r r/w r/w r/w r/w r/w initial value 0 0 n/a 0 0 0 0 0
131 8006k?avr?10/10 attiny24/44/84 between the analog comparator and the input capture function exists. to make the comparator trigger the timer/counter1 input capture inter-rupt, the icie1 bit in the timer interrupt mask register (timsk1) must be set. ? bits 1:0 ? acis1, acis0: analog comparator interrupt mode select these bits determine which comparator events that trigger the analog comparator interrupt. the different settings are shown in table 15-2 . when changing the acis1/acis0 bits, the analog comparator interrupt must be disabled by clearing its interrupt enable bit in the acsr register. otherwise an interrupt can occur when the bits are changed. 15.2.2 adcsrb ? adc control and status register b ? bit 6 ? acme: analog comparator multiplexer enable when this bit is written logic one and the adc is switched off (aden in adcsra is zero), the adc multiplexer selects the negative input to the analog comparator. when this bit is written logic zero, ain1 is applied to the negative input of the analog comparator. for a detailed description of this bit, see ?analog comparator multiplexed input? on page 129 . 15.2.3 didr0 ? digital in put disable register 0 ? bits 2:1 ? adc2d, adc1d: adc 2/1 digital input buffer disable when this bit is written logic one, the digital input buffer on the ain1/0 pin is disabled. the corre- sponding pin register bit will alwa ys read as zero when this bit is set. when an analog signal is applied to the ain1/0 pin and the digital input from this pin is not needed, this bit should be writ- ten logic one to reduce power consumption in the digital input buffer. table 15-2. acis1/acis0 settings acis1 acis0 interrupt mode 0 0 comparator interrupt on output toggle. 01reserved 1 0 comparator interrupt on falling output edge. 1 1 comparator interrupt on rising output edge. bit 7 6543210 0x03 (0x23) bin acme ? adlar ? adts2 adts1 adts0 adcsrb read/write r/w r/w r r/w r r/w r/w r/w initial value 0 0000000 bit 76543210 0x01 (0x21) adc7d adc6d adc5d adc4d adc3d adc2d adc1d adc0d didr0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
132 8006k?avr?10/10 attiny24/44/84 16. analog to digital converter 16.1 features ? 10-bit resolution ? 1.0 lsb integral non-linearity ? 2 lsb absolute accuracy ? 13s conversion time ? 15 ksps at maximum resolution ? eight multiplexed single ended input channels ? twelve differential input channels with selectable gain (1x, 20x) ? temperature sensor input channel ? optional left adjustment for adc result readout ? 0 - v cc adc input voltage range ? 1.1v adc reference voltage ? free running or single conversion mode ? adc start conversion by auto tr iggering on interrupt sources ? interrupt on adc conversion complete ? sleep mode no ise canceler ? unipolar / bipolar input mode ? input polarity reversal mode 16.2 overview the attiny24/44/84 features a 10-bit successi ve approximation adc. the adc is connected to 8-pin port a for external sources. in addition to external sources internal temperature sensor can be measured by adc. analog multiplexer allows eight single-ended channels or 12 differential channels from port a. the programmable gain stage provides ampification steps 0 db (1x) and 26 db (20x) for 12 differential adc channels. the adc contains a sample and hold circuit whic h ensures that the input voltage to the adc is held at a constant level during conversion. a block diagram of the adc is shown in figure 16-1 on page 133 . internal reference voltage of nominally 1.1v is provided on-chip. alternatively, v cc can be used as reference voltage for single ended channels. ther e is also an option to use an external volt- age reference and turn-off the internal voltage reference.
133 8006k?avr?10/10 attiny24/44/84 figure 16-1. analog to digital converter block schematic 16.3 operation the adc converts an analog input voltage to a 10-bit digital value through successive approxi- mation. the minimum value represents gnd and t he maximum value represents the reference voltage.the voltage reference for the adc may be selected by writing to the refs1:0 bits in admux. the vcc supply, the aref pin or an internal 1.1v voltage reference may be selected as the adc voltage reference. the analog input channel and differential gain are selected by writing to the mux5:0 bits in admux. any of the eight adc input pins adc7:0 can be selected as single ended inputs to the adc. for differential measurements all analog i nputs next to each other can be selected as a input pair. every input is also possible to measure with adc3. t hese pairs of differential inputs are measured by adc trough the differential gain amplifier. adc conversion complete irq 8-bit data bus 15 0 adc multiplexer select (admux) adc ctrl. & status a register (adcsra) adc data register (adch/adcl) adie ada te adsc aden adif adif mux4...mux0 adps0 adps1 adps2 conversion logic 10-bit dac + - sample & hold comparator internal reference 1.1v mux decoder v cc adc7 adc6 adc5 adc4 refs1..refs0 adlar channel selection adc[9:0] adc multiplexer output prescaler trigger select adts2...adts0 interrupt flags star t + - gain selection gain amplifier neg. input mux single ended / differential selection temperature sensor adc8 bin adc3 adc2 adc1 adc0 pos. input mux agnd adc ctrl. & status b register (adcsrb) aref
134 8006k?avr?10/10 attiny24/44/84 if differential channels are selected, the differential gain stage amplifies the voltage difference between the selected input pair by the selected gain factor, 1x or 20x, according to the setting of the mux0 bit in admux. this amplified value then becomes the analog input to the adc. if sin- gle ended channels are used, the gain amplifier is bypassed altogether. the offset of the differential channels can be measure by selecting the same input for both neg- ative and positive input. offset calibration can be done for adc0, adc3 and adc7. when adc0 or adc3 or adc7 is selected as both the positive and negative input to the differential gain amplifier , the remaining offset in the gain stage and conversion circuitry can be measured directly as the result of the conversion. this figure can be subtracted from subsequent conver- sions with the same gain setting to reduce offset error to below 1 lsb. the on-chip temperature sensor is selected by writing the code ?100010? to the mux5:0 bits in admux register. the adc is enabled by setting the adc enable bit, aden in adcsra. voltage reference and input channel selections will not go into effect until aden is set. the adc does not consume power when aden is cleared, so it is recommended to switch off the adc before entering power saving sleep modes. the adc generates a 10-bit result which is pr esented in the adc data registers, adch and adcl. by default, the result is presented right adjusted, but can optionally be presented left adjusted by setting the adlar bit in adcsrb. if the result is left adjusted and no more than 8-bit precision is required, it is sufficient to read adch. otherwise, adcl must be read first, then adch, to ensure that the content of the data registers belongs to the same conversion. once adcl is read, adc access to data registers is blocked. this means that if adcl has been r ead, and a conversion completes before adch is read, neither register is updated and the result fr om the conversion is lost. when adch is read, adc access to the adch and ad cl registers is re-enabled. the adc has its own interrupt which can be triggered when a conversion completes. when adc access to the data registers is prohibited between r eading of adch and ad cl, the in terrupt will trigger even if the result is lost. 16.4 starting a conversion a single conversion is started by writing a l ogical one to the adc start conversion bit, adsc. this bit stays high as long as the conversi on is in progress and will be cleared by hardware when the conversion is completed. if a different data channel is selected while a conversion is in progress, the adc will finish the current conv ersion before performing the channel change. alternatively, a conversion can be triggered automatically by various sources. auto triggering is enabled by setting the adc auto trigger enable bi t, adate in adcsra. the trigger source is selected by setting the adc trigger select bits, adts in adcsrb (see description of the adts bits for a list of the trigger sources). when a positive edge occurs on the selected trigger signal, the adc prescaler is reset and a conversion is st arted. this provides a method of starting con- versions at fixed intervals. if the trigger signal still is set when the conversion completes, a new conversion will not be star ted. if another positive edge occurs on the trigger si gnal during con- version, the edge will be ignored. note that an interrupt flag will be set even if the specific interrupt is disabled or the global interrupt enable bit in sreg is cleared. a conversion can thus be triggered without causing an interrupt. however, the interrupt flag must be cleared in order to trigger a new conversion at the next interrupt event.
135 8006k?avr?10/10 attiny24/44/84 figure 16-2. adc auto trigger logic using the adc interrupt flag as a trigger source makes the adc start a new conversion as soon as the ongoing conversion has finished. the adc then operates in free running mode, con- stantly sampling and updating the adc data register. the first conversion must be started by writing a logical one to the adsc bit in adcs ra. in this mode the adc will perform successive conversions independently of whether the a dc interrupt flag, adif is cleared or not. if auto triggering is enabled, single conversi ons can be started by writing adsc in adcsra to one. adsc can also be used to determine if a conversion is in progress. the adsc bit will be read as one during a conversion, independently of how the conversion was started. 16.5 prescaling and conversion timing by default, the successive approximation circuitry requires an input clock frequency between 50 khz and 200 khz to get maximum resolution. if a lower resolution than 10 bits is needed, the input clock frequency to the adc can be higher than 200 khz to get a higher sample rate. it is not recommended to use a higher input clock frequency than 1 mhz. figure 16-3. adc prescaler ad s c adif s ource 1 s ource n adt s [2:0] conver s ion logic pre s caler s ta rt clk adc . . . . edge detector adate 7-bit adc pre s caler adc clock s ource ck adp s 0 adp s 1 adp s 2 ck/12 8 ck/2 ck/4 ck/ 8 ck/16 ck/ 3 2 ck/64 re s et aden s tart
136 8006k?avr?10/10 attiny24/44/84 the adc module contains a prescaler, as illustrated in figure 16-3 on page 135 , which gener- ates an acceptable adc clock frequency fr om any cpu frequency above 100 khz. the prescaling is set by the adps bits in adcsra. the prescaler starts counting from the moment the adc is switched on by setting the aden bit in adcsra. the prescaler keeps running for as long as the aden bit is set, and is continuously reset when aden is low. when initiating a single ended conversion by se tting the adsc bit in adcsra, the conversion starts at the following rising edge of the adc clock cycle. a normal conversion takes 13 adc clock cycles. the first conversion after the adc is switched on (aden in adcsra is set) takes 25 adc clock cycles in order to initialize the analog circuitry, as shown in figure 16-4 below. figure 16-4. adc timing diagram, first conver sion (single conversion mode) the actual sample-and-hold takes place 1.5 adc clock cycles after the start of a normal conver- sion and 13.5 adc clock cycles after the start of an first conv ersion. when a conversion is complete, the result is written to the adc data re gisters, and adif is set. in single conversion mode, adsc is cleared simultaneously. the software may then set adsc again, and a new conversion will be init iated on the first rising adc clock edge. figure 16-5. adc timing diagram, single conversion s ign a nd m s b of re su lt l s b of re su lt adc clock ad s c sa mple & hold adif adch adcl cycle n u m b er aden 1 212 1 3 14 15 16 17 1 8 19 20 21 22 2 3 24 25 1 2 fir s t conver s ion next conver s ion 3 mux a nd ref s upd a te mux a nd ref s upd a te conver s ion complete 1 2 3 4 5 6 7 8 9 10 11 12 1 3 s ign a nd m s b of re su lt l s b of re su lt adc clock ad s c adif adch adcl cycle n u m b er 12 one conver s ion next conver s ion 3 sa mple & hold mux a nd ref s upd a te conver s ion complete mux a nd ref s upd a te
137 8006k?avr?10/10 attiny24/44/84 when auto triggering is used, the prescaler is reset when the trigger event occurs, as shown in figure 16-6 below. this assures a fixed delay from the trigger event to the start of conversion. in this mode, the sample-and-hold takes place two adc clock cycles after the rising edge on the trigger source signal. three additional cpu clock cycles are used for synchronization logic. figure 16-6. adc timing diagram, auto triggered conversion in free running mode, a new conversion will be started immediately after the conversion com- pletes, while adsc remains high. see figure 16-7 . figure 16-7. adc timing diagram, free running conversion 1 2 3 4 5 6 7 8 9 10 11 12 1 3 s ign a nd m s b of re su lt l s b of re su lt adc clock trigger s o u rce adif adch adcl cycle n u m b er 12 one conver s ion next conver s ion conver s ion complete pre s c a ler re s et adate pre s c a ler re s et sa mple & hold mux a nd ref s upd a te 12 1 3 14 s ign a nd m s b of re su lt l s b of re su lt adc clock ad s c adif adch adcl cycle n u m b er 12 one conver s ion next conver s ion 3 4 conver s ion complete sa mple & hold mux a nd ref s upd a te
138 8006k?avr?10/10 attiny24/44/84 for a summary of conversion times, see table 16-1 . 16.6 changing channel or reference selection the mux5:0 and refs1:0 bits in the admux register are single buffered through a temporary register to which the cpu has random access. this ensures that the channels and reference selection only takes place at a safe point dur ing the conversion. the channel and reference selection is continuously updated until a conversion is started. once the conversion starts, the channel and reference selection is locked to ensure a sufficient sampling time for the adc. con- tinuous updating resumes in the last adc clock cycle before the conversion completes (adif in adcsra is set). note that the conversion star ts on the following rising adc clock edge after adsc is written. the user is thus advised not to write new channel or reference selection values to admux until one adc clock cycle after adsc is written. if auto triggering is used, the exact time of t he triggering event can be indeterministic. special care must be taken when updating the admux register, in order to control which conversion will be affected by the new settings. if both adate and aden is written to one, an interrupt event can occur at any time. if the admux register is changed in this period, the user cannot tell if the next conversion is based on the old or the new settings. admux can be safely updated in the following ways: ? when adate or aden is cleared. ? during conversion, minimum one adc clock cycle after the trigger event. ? after a conversion, before the interrupt flag used as trigger source is cleared. when updating admux in one of these conditions, the new settings will affect the next adc conversion. 16.6.1 adc input channels when changing channel selections, the user should observe the following guidelines to ensure that the correct channel is selected: in single conversion mode, always select the channel before starting the conversion. the chan- nel selection may be changed one adc clock cycle after writing one to adsc. however, the simplest method is to wait for the conversion to complete before changing the channel selection. in free running mode, always select the channel before starting the first conversion. the chan- nel selection may be changed one adc clock cycle after writing one to adsc. however, the simplest method is to wait for the first conversion to complete, and then change the channel table 16-1. adc conversion time condition sample & hold (cycles from start of conversion) conversion time (cycles) first conversion 13.5 25 normal conversions 1.5 13 auto triggered conversions 2 13.5 free running conversion 2.5 14
139 8006k?avr?10/10 attiny24/44/84 selection. since the next conver sion has already started automati cally, the next result will reflect the previous channel selection. subsequent conversions will refl ect the new channel selection. 16.6.2 adc voltage reference the reference voltage for the adc (v ref ) indicates the conversion range for the adc. single ended channels that exceed v ref will result in code s close to 0x3ff. v ref can be selected as either v cc , or internal 1.1v reference, or external aref pin. the first adc conversion result after switching reference voltage source may be inaccurate, and the user is advised to discard this result. 16.7 adc noise canceler the adc features a noise canceler that enables conversion during sleep mode. this reduces noise induced from the cpu core and other i/o peripherals. the noise canceler can be used with adc noise reduction and idle mode. to make use of this feature, the following procedure should be used: ? make sure that the adc is enabled and is not busy converting. single conversion mode must be selected and the adc conversion complete interrupt must be enabled. ? enter adc noise reduction mode (or idle mode ). the adc will start a conversion once the cpu has been halted. ? if no other interrupts occur be fore the adc conversion comple tes, the adc interrupt will wake up the cpu and execute the adc conversion complete interrupt routine. if another interrupt wakes up the cpu before the adc conversion is complete, that interrupt will be executed, and an adc conversion complete interrup t request will be gene rated when the adc conversion completes. the cpu will remain in active mode until a new sleep command is executed. note that the adc will not automatically be turned off when entering other sleep modes than idle mode and adc noise reduction mode. the user is advised to write zero to aden before enter- ing such sleep modes to avoid excessive power consumption. 16.8 analog input circuitry the analog input circuitry for sing le ended channels is illustrated in figure 16-8 on page 140 . an analog source applied to adcn is subjected to the pin capacitance and input leakage of that pin, regardless of whether that channel is select ed as input for the adc. when the channel is selected, the source must drive the s/h capacito r through the series resistance (combined resis- tance in the input path). the adc is optimized for analog signals with an output impedance of approximately 10k or less. if such a source is used, the sampling time will be negligible. if a source with higher imped- ance is used, the sampling time will depend on how long time the source nee ds to charge the s/h capacitor, which can vary widely. with sl owly varying signals the user is recommended to use sources with low impedance, only, since this minimizes the required charge transfer to the s/h capacitor. signal components higher than the nyquist frequency (f adc /2) should not be present to avoid distortion from unpredictable signal convolution. the user is advised to remove high frequency components with a low-pass filter before applying the signals as inputs to the adc.
140 8006k?avr?10/10 attiny24/44/84 figure 16-8. analog input circuitry note: the capacitor in the figure depicts the total capacitance, including the sample/hold capacitor and any stray or parasitic capacitance inside the device. the value given is worst case. 16.9 noise canceling techniques digital circuitry inside and outside the device ge nerates emi which might affect the accuracy of analog measurements. when conversion accuracy is critical, the noise level can be reduced by applying the following techniques: ? keep analog signal paths as short as possible. ? make sure analog tracks run over the analog ground plane. ? keep analog tracks well away from high-speed switching digital tracks. ? if any port pin is used as a digital output, it mustn?t switch while a conversion is in progress. ? place bypass capacitors as close to v cc and gnd pins as possible. where high adc accuracy is required it is recommended to use adc noise reduction mode, as described in section 16.7 on page 139 . this is especially the case when system clock frequency is above 1 mhz, or when the adc is used for reading the internal temperature sensor, as described in section 16.12 on page 144 . a good system design with properly placed, external bypass capacitors does reduce the need for using adc noise reduction mode 16.10 adc accuracy definitions an n-bit single-ended adc converts a voltage linearly between gnd and v ref in 2 n steps (lsbs). the lowest code is read as 0, and the highest code is read as 2 n -1. several parameters describe the deviation from the ideal behavior, as follows: adcn i ih 1..100 k ohm c s/h = 14 pf v cc /2 i il
141 8006k?avr?10/10 attiny24/44/84 ? offset: the deviation of the first transition (0x000 to 0x001) compared to the ideal transition (at 0.5 lsb). ideal value: 0 lsb. figure 16-9. offset error ? gain error: after adjusting for offset, the gain error is found as the deviation of the last transition (0x3fe to 0x3ff) compared to the ideal transition (at 1.5 lsb below maximum). ideal value: 0 lsb figure 16-10. gain error o u tp u t code v ref inp u t volt a ge ide a l adc act ua l adc off s et error o u tp u t code v ref inp u t volt a ge ide a l adc act ua l adc g a in error
142 8006k?avr?10/10 attiny24/44/84 ? integral non-linearity (inl): after adjusting for offset and gain error, the inl is the maximum deviation of an actual transition compared to an ideal transition for any code. ideal value: 0 lsb. figure 16-11. integral non-linearity (inl) ? differential non-linearity (dnl): the maximum deviation of the actual code width (the interval between two adjacent transitions) from the ideal code width (1 lsb). ideal value: 0 lsb. figure 16-12. differential non-linearity (dnl) o u tp u t code v ref inp u t volt a ge ide a l adc act ua l adc inl o u tp u t code 0x 3 ff 0x000 0 v ref inp u t volt a ge dnl 1 l s b
143 8006k?avr?10/10 attiny24/44/84 ? quantization error: due to the quantization of the input voltage into a finite number of codes, a range of input voltages (1 lsb wide) will code to the same value. always 0.5 lsb. ? absolute accuracy: the maximum deviation of an actual (unadjusted) transition compared to an ideal transition for any code. this is the compound effect of offset, gain error, differential error, non-linearity, and quantization error. ideal value: 0.5 lsb. 16.11 adc conversion result after the conversion is complete (adif is high ), the conversion result can be found in the adc result registers (adcl, adch) . the form of the conversion result depends on the type of the conversio as there are three types of conversions: single ended c onversion, unipolar differential conversion and bipolar differential conversion. 16.11.1 single ended conversion for single ended conversion, the result is where v in is the voltage on the selected input pin and v ref the selected voltage reference (see table 16-3 on page 145 and table 16-4 on page 146 ). 0x000 represents analog ground, and 0x3ff represents the selected reference voltage minus one lsb. the result is presented in one- sided form, from 0x3ff to 0x000. 16.11.2 unipolar differential conversion if differential channels and an unipolar input mode are used, the result is where v pos is the voltage on the positive input pin, v neg the voltage on the negative input pin, and v ref the selected voltage reference. the voltage of the positive pin must always be larger than the voltage of the negative pin or otherwise the voltage difference is saturated to zero. the result is presented in one-sided form, from 0x000 (0d) through 0x3ff (+1023d). the gain is either 1x or 20x. 16.11.3 bipolar differential conversion if differential channels and a bipolar input mode are used, the result is where v pos is the voltage on the positive input pin, v neg the voltage on the negative input pin, and v ref the selected voltage reference. the result is presented in two?s complement form, from 0x200 (-512d) through 0x1ff (+511d). the gain is ei ther 1x or 20x. note that if the user wants adc v in 1024 ? v ref -------------------------- = adc v pos v neg ? () 1024 ? v ref ------------------------------------------------------- - gain ? = adc v pos v neg ? () 512 ? v ref ---------------------------------------------------- - gain ? =
144 8006k?avr?10/10 attiny24/44/84 to perform a quick polarity check of the result, it is sufficient to read the msb of the result (adc9 in adch). if the bit is one, the result is negative, and if this bit is zero, the result is positive. as default the adc converter operates in the unipolar input mode, but the bipolar input mode can be selected by writting the bin bit in the adcsrb to one. in the bipolar input mode two- sided voltage differences are allowed and thus the voltage on the negative input pin can also be larger than the voltage on the positive input pin. 16.12 temperature measurement the temperature measurement is based on an on-ch ip temperature sensor that is coupled to a single ended adc8 channel. selecting the adc8 channel by writing the mux5:0 bits in admux register to ?100010? enables the temperature sensor. the internal 1.1v reference must also be selected for the adc reference source in the temperature sensor measurement. when the tem- perature sensor is enabled, the adc converte r can be used in single conversion mode to measure the voltage over the temperature sensor. the measured voltage has a linear relationship to the temperature as described in table 16-2 the sensitivity is approximately 1 lsb / c and the accuracy depends on the method of user cal- ibration. typically, the measurement accuracy after a single temperature calibration is 10 c, assuming calibration at room temperature. better accuracies are achieved by using two temperature points for calibration. the values described in table 16-2 are typical values. however, due to process variation the temperature sensor output voltage varies from one chip to another. to be capable of achieving more accurate results the temperature measurement can be calibrated in the application soft- ware. the sofware calibration can be done using the formula: t = k * [(adch << 8) | adcl] + t os where adch and adcl are the adc data registers, k is the fixed slope coefficient and t os is the temperature sensor offset. typically, k is very close to 1.0 and in single-point calibration the coefficient may be omitted. where higher accura cy is required the slope coefficient should be evaluated based on measurements at two temperatures. table 16-2. temperature vs. sensor output voltage (typical case) temperature -40 c+25 c+85 c adc 230 lsb 300 lsb 370 lsb
145 8006k?avr?10/10 attiny24/44/84 16.13 register description 16.13.1 admux ? adc multiplexer selection register ? bits 7:6 ? refs1, refs0: reference selection bits these bits select the voltage reference for the adc, as shown in table 16-3 . if these bits are changed during a conversion, the change will not go in effect until this conversion is complete (adif in adcsr is se t). also note, that when these bits are changed, the next conversion will take 25 adc clock cycles. special care should be taken when changing differential channels. once a differential channel has been selected the input sta ge may take a while to stabilize. it is therefor e recommended to force the adc to perform a long conversion when changing multiplexer or voltage reference set- tings. this can be done by first turning off t he adc, then changing reference settings and then turn on the adc. alternatively, the first conv ersion results after changing reference settings should be discarded. it is not recommended to use an external aref higher than (v cc - 1v) for channels with differ- ential gain, as this will affect adc accuracy. internal voltage reference options may not be used if an external voltage is being applied to the aref pin. ? bits 5:0 ? mux5:0: analog channel and gain selection bits the value of these bits selects which combination of analog inputs are connected to the adc. in case of differential input, gain selection is also made with these bits. selections on table 16-4 on page 146 show values for single endid channels and where the differential channels as well as the offset calibration selections are loca ted. selecting the single-ended channel adc8 enables the temperature measurement. see table 16-4 on page 146 for details. if these bits are changed during a conversion, the change will not go into effect unt il this conversion is complete (adif in adcsra is set). special care should be taken when changing differential channels. once a differential channel has been selected the input sta ge may take a while to stabilize. it is therefor e recommended to force the adc to perform a long conversion wh en changing multiplexer settings. this can be bit 76543210 0x07 (0x27) refs1 refs0 mux5 mux4 mux3 mux2 mux1 mux0 admux read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 16-3. voltage reference selections for adc refs1 refs0 voltage reference selection 00v cc used as analog reference, disconnected from pa0 (aref) 0 1 external voltage reference at pa0 (are f) pin, internal reference turned off 1 0 internal 1.1v voltage reference 11reserved
146 8006k?avr?10/10 attiny24/44/84 done by first turning off the ad c, then changing multiplexer settings and then turn on the adc. alternatively, the first conversion results after ch anging multiplexer settings should be discarded. notes: 1. see table 16-5 for details. 2. after switching to internal voltage reference the adc requires a settling time of 1ms before measurements are stable. conversions starting before this may not be reliable. the adc must be enabled during the settling time. 3. see ?temperature measurement? on page 144 . 4. for offset calibration, only. see table 16-5 on page 146 and ?operation? on page 133 . see table 16-5 for details of selections of differential input channel selections as well as selec- tions of offset calibration channels. mux0 bit works as a gain selection bit for differential channels. when mux0 is cleared (?0?) 1x gain is selected and when it is set (?1?) 20x gain is selected. for normal differential channel pairs mux5 bit work as a polarity reversal bit. toggling of the mux5 bit exhanges the positive and negative channel other way a round. table 16-4. single-ended input channel selections. single ended input mux5:0 adc0 (pa0) 000000 adc1 (pa1) 000001 adc2 (pa2) 000010 adc3 (pa3) 000011 adc4 (pa4) 000100 adc5 (pa5) 000101 adc6 (pa6) 000110 adc7 (pa7) 000111 reserved for differential channels (1) 001000 - 011111 0v (agnd) 100000 1.1v (i ref) (2) 100001 adc8 (3) 100010 reserved for offset calibration (4) 100011 - 100111 reserved for reversal differential channels (1) 101000 - 111111 table 16-5. differential input ch annel selections. positive differential input negative differential input mux5:0 gain 1x gain 20x adc0 (pa0) adc0 (pa0) (1) n/a 100011 adc1 (pa1) 001000 001001 adc3 (pa3) 001010 001011 adc1 (pa1) adc0 (pa0) 101000 101001 adc2 (pa2) 001100 001101 adc3 (pa3) 001110 001111
147 8006k?avr?10/10 attiny24/44/84 for offset calibration purpose the offset of the certain differential channels can be measure by selecting the same input for both negative and positive input. this calibration can be done for adc0, adc3 and adc7. ?operation? on page 133 describes offset calibration in a more detailed level. 16.13.2 adcsra ? adc control and status register a ? bit 7 ? aden: adc enable writing this bit to one enables the adc. by writi ng it to zero, the adc is turned off. turning the adc off while a conversion is in prog ress, will terminate this conversion. adc2 (pa2) adc1 (pa1) 101100 101101 adc3 (pa3) 010000 010001 adc3 (pa3) adc0 (pa0) 101010 101011 adc1 (pa1) 101110 101111 adc2 (pa2) 110000 110001 adc3 (pa3) (1) 100100 100101 adc4 (pa4 010010 010011 adc5 (pa5) 010100 010101 adc6 (pa6) 010110 010111 adc7 (pa7) 011000 011001 adc4 (pa4) adc3 (pa3) 110010 110011 adc5 (pa5) 011010 011011 adc5 (pa5) adc3 (pa3) 110100 110101 adc4 (pa4) 111010 111011 adc6 (pa6) 011100 011101 adc6 (pa6) adc3 (pa3) 110110 110111 adc5 (pa5) 111100 111101 adc7 (pa7) 011110 011111 adc7 (pa7) adc3 (pa3) 111000 111001 adc6 (pa6) 111110 111111 adc7 (pa7) (1) 100110 100111 1. for offset calibration, only. see ?operation? on page 133 . table 16-5. differential input channel selections. (continued) positive differential input negative differential input mux5:0 gain 1x gain 20x bit 76543210 0x06 (0x26) aden adsc adate adif adie adps2 adps1 adps0 adcsra read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
148 8006k?avr?10/10 attiny24/44/84 ? bit 6 ? adsc: adc start conversion in single conversion mode, write this bit to one to start each conversion. in free running mode, write this bit to one to start the first conversion. the first conversion after adsc has been written after the adc has been enabled, or if adsc is written at the same time as the adc is enabled, will take 25 adc clock cycles instead of the norma l 13. this first conversi on performs initializa- tion of the adc. adsc will read as one as long as a conversion is in progress. when the co nversion is complete, it returns to zero. writing zero to this bit has no effect. ? bit 5 ? adate: adc auto trigger enable when this bit is written to on e, auto triggering of the adc is enabled. the adc will start a con- version on a positive edge of the selected trigger signal. the trigger source is selected by setting the adc trigger select bits, adts in adcsrb. ? bit 4 ? adif: adc interrupt flag this bit is set when an adc conversion completes and the data registers are updated. the adc conversion complete interrupt is executed if th e adie bit and the i-bit in sreg are set. adif is cleared by hardware when executing the corres ponding interrupt handling vector. alternatively, adif is cleared by writing a logical one to the flag. beware that if doing a read-modify-write on adcsra, a pending interrupt can be disabled. this also applies if the sbi instruction is used. ? bit 3 ? adie: adc interrupt enable when this bit is written to one and the i-bit in sreg is set, the adc conversion complete inter- rupt is activated. ? bits 2:0 ? adps2:0: adc prescaler select bits these bits determine the division factor betwee n the system clock frequency and the input clock to the adc. table 16-6. adc prescaler selections adps2 adps1 adps0 division factor 000 2 001 2 010 4 011 8 100 16 101 32 110 64 111 128
149 8006k?avr?10/10 attiny24/44/84 16.13.3 adcl and adch ? adc data register 16.13.3.1 adlar = 0 16.13.3.2 adlar = 1 when an adc conversion is complete, the result is found in these two registers. when adcl is read, the adc data register is not updated unt il adch is read. consequently, if the result is left adjusted and no more than 8-bit precision is required, it is sufficient to read adch. otherwise, adcl must be read first, then adch. the adlar bit in adcsrb, and the muxn bits in admux affect the way the result is read from the registers. if adlar is set, the result is left adjusted. if adla r is cleared (default), the result is right adjusted. ? adc9:0: adc conversion result these bits represent the result from the conversion, as detailed in ?adc conversion result? on page 143 . 16.13.4 adcsrb ? adc control and status register b ? bit 7 ? bin: bipolar input mode the gain stage is working in the unipolar mode as default, but the bipolar mode can be selected by writing the bin bit in the adcsrb register. in the unipolar mode only one-sided conversions are supported and the voltage on the positive input must always be larger than the voltage on the negative input. otherwise the result is saturated to the voltage reference. in the bipolar mode two-sided conversions are supported and the result is represented in the two?s complement form. in the unipolar mode the resolution is 10 bits and the bipolar mode the resolution is 9 bits + 1 sign bit. bit 151413121110 9 8 0x05 (0x25) ? ? ? ? ? ? adc9 adc8 adch 0x04 (0x24) adc7 adc6 adc5 adc4 adc3 adc2 adc1 adc0 adcl 76543210 read/write rrrrrrrr rrrrrrrr initial value 0 0 0 0 0 0 0 0 00000000 bit 151413121110 9 8 0x05 (0x25) adc9 adc8 adc7 adc6 adc5 adc4 adc3 adc2 adch 0x04 (0x24) adc1 adc0 ? ? ? ? ? ? adcl 76543210 read/write rrrrrrrr rrrrrrrr initial value 0 0 0 0 0 0 0 0 00000000 bit 76543210 0x03 (0x23) bin acme ? adlar ? adts2 adts1 adts0 adcsrb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 00000000
150 8006k?avr?10/10 attiny24/44/84 ? bit 6 ? acme: analog comparator multiplexer enable see ?adcsrb ? adc control and status register b? on page 131 . ? bit 5 ? res: reserved bit this is a reserved bit in attiny24/44/84. for comp atibility with future devices always write this bit to zero. ? bit 4 ? adlar: adc left adjust result the adlar bit affects the presentation of the adc conversion result in the adc data register. write one to adlar to left adjust the result. otherwise, the result is right adjusted. changing the adlar bit will affect t he adc data register immediately, regardless of any ongoing conver- sions. for a comple the description of this bit, see ?adcl and adch ? adc data register? on page 149 . ? bit 3 ? res: reserved bit this bit is reserved bit in the attiny24/44/ 84 and will always read as what was wrote there. ? bits 2:0 ? adts2:0: adc auto trigger source if adate in adcsra is written to one, the value of these bits selects which source will trigger an adc conversion. if adate is cleared, the adts2:0 settings will have no effect. a conversion will be triggered by the risi ng edge of the selected interrupt flag . note that switch ing from a trig- ger source that is cleared to a trigger source that is set, will generate a positive edge on the trigger signal. if aden in adcsra is set, this will start a conversion. switching to free running mode (adts[2:0]=0) will not cause a trigger event, even if t he adc interrupt flag is set . 16.13.5 didr0 ? digital input disable register 0 ? bits 7:0 ? adc7d:adc0d: adc7 :0 digital input disable when a bit is written logic one, the digital input buffer on the corresponding adc pin is disabled. the corresponding pin register bi t will always read as zero when th is bit is set. when an analog signal is applied to the adc7:0 pin and the digital input from this pin is not needed, this bit should be written logic one to reduce power consumption in the digital input buffer. table 16-7. adc auto trigger source selections adts2 adts1 adts0 trigger source 0 0 0 free running mode 0 0 1 analog comparator 0 1 0 external interrupt request 0 0 1 1 timer/counter0 compare match a 1 0 0 timer/counter0 overflow 1 0 1 timer/counter1 compare match b 1 1 0 timer/counter1 overflow 1 1 1 timer/counter1 capture event bit 76543210 0x01 (0x21) adc7d adc6d adc5d adc4d adc3d adc2d adc1d adc0d didr0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
151 8006k?avr?10/10 attiny24/44/84 17. debugwire on-chip debug system 17.1 features ? complete program flow control ? emulates all on-chip functions, both digital and an alog , except reset pin ? real-time operation ? symbolic debugging support (both at c and assembler source level, or for other hlls) ? unlimited number of prog ram break points (using software break points) ? non-intrusive operation ? electrical characteristics identical to real device ? automatic configuration system ? high-speed operation ? programming of non-volatile memories 17.2 overview the debugwire on-chip debug system uses a one-wire, bi-directional interface to control the program flow, execute avr instructions in the cpu and to program the different non-volatile memories. 17.3 physical interface when the debugwire enable (dwen) fuse is programmed and lock bits are unprogrammed, the debugwire system within the target device is activated. the reset port pin is configured as a wire-and (open-drain) bi-directional i/o pin with pull-up enabled and becomes the commu- nication gateway between target and emulator. figure 17-1 shows the schematic of a target mcu, with debugwire enabled, and the emulator connector. the system clock is not affected by debugwire and will always be the clock source selected by the cksel fuses. figure 17-1. the debugwire setup dw gnd dw(re s et) vcc 1. 8 - 5.5v
152 8006k?avr?10/10 attiny24/44/84 when designing a system where debugwire will be used, the following must be observed: ? pull-up resistor on the dw/(reset) line must be in the ra nge of 10k to 20 k . however, the pull-up resistor is optional. ? connecting the reset pin directly to v cc will not work. ? capacitors inserted on the reset pin must be disconnected when using debugwire. ? all external reset sources must be disconnected. 17.4 software break points debugwire supports program memory break points by the avr break instruction. setting a break point in avr studio ? will insert a break instruction in the program memo ry. the instruc- tion replaced by the break instru ction will be stored. when program execution is continued, the stored instruction will be execut ed before continuing from the program memory. a break can be inserted manually by putting the break instruction in the program. the flash must be re-programmed each time a break point is changed. this is automatically handled by avr studio th rough the debugwire inte rface. the use of brea k points will therefore reduce the falsh data retention. devices used for debugging purposes should not be shipped to end customers. 17.5 limitations of debugwire the debugwire communication pin (dw) is physica lly located on the same pin as external reset (reset). an external reset source is therefore not supported when the debugwire is enabled. the debugwire system accurately emulates all i/ o functions when running at full speed, i.e., when the program in the cpu is running. when the cpu is stopped, care must be taken while accessing some of the i/o registers via the debugger (avr studio). see the debugwire docu- mentation for detailed description of the limitations. the debugwire interface is asynchronous, whic h means that the debugger needs to synchro- nize to the system clock. if the system clock is changed by software (e.g . by writing clkps bits) communication via debugwire may fail. also, clock frequencies below 100 khz may cause communication problems. a programmed dwen fuse enable s some parts of the clock system to be running in all sleep modes. this will increase the power consumption while in sleep. thus, the dwen fuse should be disabled when debugwire is not used. 17.6 register description the following section describes the registers used with the debugwire. 17.6.1 dwdr ? debugwire data register the dwdr register provides a communication channel from the running program in the mcu to the debugger. this register is only accessible by the debugwire and can therefore not be used as a general purpose register in the normal operations. bit 76543210 0x27 (0x47) dwdr[7:0] dwdr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
153 8006k?avr?10/10 attiny24/44/84 18. self-programming the flash the device provides a self-programming me chanism for downloading and uploading program code by the mcu itself. the self-programming ca n use any available data interface and associ- ated protocol to read code and write (program) that code into the program memory. the spm instruction is disabled by default but it ca n be enabled by programming the selfprgen fuse (to ?0?). the program memory is updated in a page by page fashion. before programming a page with the data stored in the temporary page buffer, the page must be erased. the temporary page buf- fer is filled one word at a time using spm and the buffer can be filled either before the page erase command or between a page erase and a page write operation: alternative 1, fill the bu ffer before a page erase ? fill temporary page buffer ? perform a page erase ? perform a page write alternative 2, fill the bu ffer after page erase ? perform a page erase ? fill temporary page buffer ? perform a page write if only a part of the page needs to be changed, the rest of the page must be stored (for example in the temporary page buffer) before the erase, and then be re-written. when using alternative 1, the boot loader provides an effective read-modify-write feature which allows the user software to first read the page, do the necessary changes, and then write back the modified data. if alter- native 2 is used, it is not possible to read the old data while loading since the page is already erased. the temporary page buffer can be accessed in a random sequence. it is essential that the page address used in both the page erase and page write operation is addressing the same page. 18.1 performing page erase by spm to execute page erase, set up the address in the z-pointer, write ?00000011? to spmcsr and execute spm within four clock cycles after writing spmcsr. the data in r1 and r0 is ignored. the page address must be written to pcpage in the z-register. other bits in the z-pointer will be ignored during this operation. note: the cpu is halted during the page erase operation. 18.2 filling the temporar y buffer (page loading) to write an instruction word, set up the address in the z-pointer and data in r1:r0, write ?00000001? to spmcsr and execute spm within four clock cycles after writing spmcsr. the content of pcword in the z-register is used to address the data in the temporary buffer. the temporary buffer will auto-erase after a page write operation or by writing the ctpb bit in spmcsr. it is also erased after a system reset. note that it is not possible to write more than one time to each address without erasing the temporary buffer.
154 8006k?avr?10/10 attiny24/44/84 if the eeprom is written in the middle of an spm page load operation, all data loaded will be lost. 18.3 performing a page write to execute page write, set up the address in the z-pointer, write ?00000101? to spmcsr and execute spm within four clock cycles after writing spmcsr. the data in r1 and r0 is ignored. the page address must be written to pcpage. other bits in the z-pointer must be written to zero during this operation. note: the cpu is halted during the page write operation. 18.4 addressing the flash during self-programming the z-pointer is used to address the spm commands. since the flash is organized in pages (see table 19-8 on page 162 ), the program counter can be treated as having two different sections. one sect ion, consisting of the least significant bits, is addressing the words within a page, while the most significant bits are addressing the pages. this is shown in figure 19-1 on page 163 . note that the page erase and page write operations are addressed independently. therefore it is of major importance that the software addresses the same page in both the page erase and page write operation. the lpm instruction uses the z-pointer to store the address. since this instruction addresses the flash byte-by-byte, also the lsb (bit z0) of the z-pointer is used. figure 18-1. addressing the flash during spm note: the variables used in figure 18-1 are listed in table 19-8 on page 162 . bit 151413121110 9 8 zh (r31) z15 z14 z13 z12 z11 z10 z9 z8 zl (r30) z7z6z5z4z3z2z1z0 76543210 program memory 0 1 15 z - register bit 0 zpagemsb word address within a page page address within the flash zpcmsb instruction word pag e pcword[pagemsb:0]: 00 01 02 pageend pag e pcword pcpage pcmsb pagemsb program counter
155 8006k?avr?10/10 attiny24/44/84 18.5 eeprom write prevent s writing to spmcsr note that an eeprom write oper ation will block all software progra mming to flash. reading the fuses and lock bits from software will also be prevented during the eeprom write operation. it is recommended that the user checks the status bit (eepe) in the eecr register and verifies that the bit is cleared before writing to the spmcsr register. 18.6 reading lock, fuse and signat ure data from software it is possible for firmware to read device fuse and lock bits. in addition, firmware can also read data from the device signature imprint table (see page 161 ). note: fuse and lock bits that are programmed, will be read as zero. fuse and lock bits that are unpro- grammed, will be read as one. 18.6.1 reading lock bits from firmware lock bit values are returned in the destination register after an lpm instruction has been issued within three cpu cycles after rflb and selfp rgen bits have been set in spmcsr. the rflb and selfprgen bits automatically clear upon completion of reading the lock bits, or if no lpm instruction is executed within three cpu cycl es, or if no spm instruction is executed within four cpu cycles. when rflb and selfpr gen are cleared lpm functions normally. to read the lock bits, follow the below procedure: 1. load the z-pointer with 0x0001. 2. set rflb and selfprgen bits in spmcsr. 3. issue an lpm instruction within three clock cycles. 4. read the lock bits from the lpm destination register. if successful, the contents of the destination register are as follows. see section ?program and data memory lock bits? on page 159 for more information. 18.6.2 reading fuse bits from firmware the algorithm for reading fuse byte s is similar to the one described above for reading lock bits, only the addresses are different. to read the fuse low byte (flb), follow the below procedure: 1. load the z-pointer with 0x0000. 2. set rflb and selfprgen bits in spmcsr. 3. issue an lpm instruction within three clock cycles. 4. read the flb from the lpm destination register. if successful, the contents of the destination register are as follows. refer to table 19-5 on page 161 for a detailed description and mapping of the fuse low byte. bit 76543210 rd ??????lb2lb1 bit 76543210 rd flb7 flb6 flb5 flb4 flb3 flb2 flb1 flb0
156 8006k?avr?10/10 attiny24/44/84 to read the fuse high byte (fhb), simply repl ace the address in the z-pointer with 0x0003 and repeat the procedure above. if successful, the contents of the destination register are as follows. refer to table 19-4 on page 160 for detailed description and mapping of the fuse high byte. to read the fuse extended byte (feb), replace the address in the z-pointer with 0x0002 and repeat the previous procedure. if successful, t he contents of the destination register are as follows. refer to table 19-3 on page 160 for detailed description and mapping of the fuse extended byte. 18.6.3 reading device signature imprint table from firmware to read the contents of the device signature imprint table, follow the below procedure: 1. load the z-pointer with the table index. 2. set rsig and spmen bits in spmcsr. 3. issue an lpm instruction within three clock cycles. 4. wait three clock cycles for spmen bits to be cleared. 5. read table data from the lpm destination register. the rsig and spmen bits will auto-clear after three cpu cycles. when rsig and spmen are cleared, lpm will work as described in the ?avr instruction set? description. see program example below. note: see ?code examples? on page 6 . bit 76543210 rd fhb7 fhb6 fhb5 fhb4 fhb3 fhb2 fhb1 fhb0 bit 76543210 rd feb7 feb6 feb5 feb4 feb3 feb2 feb1 feb0 assembly code example dsit_read: ; uses z-pointer as table index ldi zh, 0 ldi zl, 1 ; preload spmcsr bits into r16, then write to spmcsr ldi r16, (1< 157 8006k?avr?10/10 attiny24/44/84 if successful, the contents of the destination register are as described in section ?device signa- ture imprint table? on page 161 . 18.7 preventing fl ash corruption during periods of low v cc , the flash program can be corrupted because the supply voltage is too low for the cpu and the flash to operate properly. these issues are the same as for board level systems using the flash, and the same design solutions should be applied. a flash program corruption can be caused by two situ ations when the voltage is too low. first, a regular write sequence to the flash requires a minimum voltage to operate correctly. secondly, the cpu itself can execute instruct ions incorrectly, if the supply voltage for executing instructions is too low. flash corruption can easily be avoided by following these design recommendations (one is sufficient): 1. keep the avr reset active (low) during peri ods of insufficient po wer supply voltage. this can be done by enabling the internal brown-out detector (bod) if the operating voltage matches the detection level. if not, an external low v cc reset protection circuit can be used. if a reset occurs while a write operation is in progress, the write operation will be completed provided that the power supply voltage is sufficient. 2. keep the avr core in power-down sleep mode during periods of low v cc . this will pre- vent the cpu from attempting to decode and execute instructions, effectively protecting the spmcsr register and thus the flash from unintentional writes. 18.8 programming time fo r flash when using spm the calibrated rc oscillator is used to time flash accesses. table 18-1 shows the typical pro- gramming time for flash accesses from the cpu. note: 1. the min and max programming times is per individual operation. 18.9 register description 18.9.1 spmcsr ? store program memory control and status register the store program memory control and status register contains the control bits needed to con- trol the program memory operations. ? bits 7:6 ? res: reserved bits these bits are reserved in the attiny 24/44/84 and will always read as zero. table 18-1. spm programming time (1) symbol min programming time max programming time flash write (page erase, page write, and write lock bits by spm) 3.7 ms 4.5 ms bit 7 65 4 3 210 0x37 (0x57) ? ? rsig ctpb rflb pgwrt pgers spmen spmcsr read/write r r r r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
158 8006k?avr?10/10 attiny24/44/84 ? bit 5 ? rsig: read device signature imprint table issuing an lpm inst ruction within three cycles after rsig and spmen bits have been set in spmcsr will return the selected dat a (depending on z-pointer valu e) from the device signature imprint table into the de stination register. see ?device signature imprint table? on page 161 for details. ? bit 4 ? ctpb: clear temporary page buffer if the ctpb bit is writte n while filling the temporary page bu ffer, the temporary page buffer will be cleared and the da ta will be lost. ? bit 3 ? rflb: read fuse and lock bits an lpm instruction within three cycles after rflb and spmen are set in the spmcsr register, will read either the lock bits or t he fuse bits (depending on z0 in the z-pointer) in to the destina- tion register. see ?eeprom write preven ts writing to spmcsr? on page 155 for details. ? bit 2 ? pgwrt: page write if this bit is written to one at the same time as spmen, the next spm instruction within four clock cycles executes page write, with the data stored in the temporary buffer. the page address is taken from the high part of the z-pointer. the data in r1 and r0 are ignored. the pgwrt bit will auto-clear upon co mpletion of a page write, or if no spm instruction is ex ecuted within four clock cycles. the cpu is halted during the entire page write operation. ? bit 1 ? pgers: page erase if this bit is written to one at the same time as spmen, the next spm instruction within four clock cycles executes page erase. the page address is taken from the high part of the z-pointer. the data in r1 and r0 are ignored. the pgers bi t will auto-clear upon comp letion of a page erase, or if no spm instruction is executed within four clock cycles. the cpu is halted during the entire page write operation. ? bit 0 ? spmen: store program memory enable this bit enables the spm instruction for the next four clock cycles. if set to one together with rsig, ctpb, rflb, pgwrt or pgers, the follo wing lpm/spm instructi on will have a special meaning, as described elsewhere. if only spmen is written, the following spm inst ruction will store the value in r1:r0 in the tem- porary page buffer addressed by the z-pointer. the lsb of the z-pointer is ignored. the spmen bit will auto-clear upon completion of an spm instruction, or if no spm instruction is executed within four clock cycles. during page erase and page write, the spmen bit remains high until the operation is completed.
159 8006k?avr?10/10 attiny24/44/84 19. memory programming this section describes the different methods for programming attiny24/44/84 memories. 19.1 program and data memory lock bits the attiny24/44/84 provides two lock bits which can be left unprogrammed (?1?) or can be pro- grammed (?0?) to obtain the additional security listed in table 19-2 . the lock bits can only be erased to ?1? with the chip erase command. the device has no separate boot loader section. the spm instruction is enabled for the whole flash, if the selfprgen fuse is programmed (?0?), otherwise it is disabled. program memory can be read out via the debugwire interface when the dwen fuse is pro- grammed, even if lock bits are set. thus, when lock bit security is required, debugwire should always be disabled by clearing the dwen fuse. note: ?1? means unprogrammed, ?0? means programmed. notes: 1. program fuse bits before programming lb1 and lb2. 2. ?1? means unprogrammed, ?0? means programmed lock bits can also be read by device firmware. see section ?reading lock, fuse and signature data from software? on page 155 . table 19-1. lock bit byte lock bit bit no description default value 7 ? 1 (unprogrammed) 6 ? 1 (unprogrammed) 5 ? 1 (unprogrammed) 4 ? 1 (unprogrammed) 3 ? 1 (unprogrammed) 2 ? 1 (unprogrammed) lb2 1 lock bit 1 (unprogrammed) lb1 0 lock bit 1 (unprogrammed) table 19-2. lock bit protection modes. memory lock bits (1) (2) protection type lb mode lb2 lb1 1 1 1 no memory lock features enabled. 210 further programming of the flash and eeprom is disabled in high-voltage and serial programming mode. the fuse bits are locked in both serial and high-voltage programming mode. (1) debugwire is disabled. 300 further programming and verification of the flash and eeprom is disabled in high-voltage and serial programming mode. the fuse bits are locked in both serial and high-voltage programming mode. (1) debugwire is disabled.
160 8006k?avr?10/10 attiny24/44/84 19.2 fuse bytes the attiny24/44/84 have three fuse bytes. table 19-3 , table 19-4 and table 19-5 briefly describe the functionality of all the fuses and how they are mapped into the fuse bytes. note that the fuses are read as logical zero, ?0?, if they are programmed. notes: 1. enables spm instruction. see ?self-programming the flash? on page 153 . notes: 1. see ?alternate functions of port b? on page 65 for description of rstdisbl and dwen fuses. after programming the rstdisbl fuse, high-voltage serial programming must be used to change fuses and allow further programming. 2. dwen must be unprogrammed when lock bit security is required. see ?program and data memory lock bits? on page 159 . 3. the spien fuse is not accessible in spi programming mode. 4. programming this fues will disable the watchdog timer interrupt. see ?wdt configuration as a function of the fuse settings of wdton? on page 43 for details. 5. see table 20-7 on page 179 for bodlevel fuse decoding. table 19-3. fuse extended byte fuse extended byte bit no description default value 7 - 1 (unprogrammed) 6 - 1 (unprogrammed) 5 - 1 (unprogrammed) 4 - 1 (unprogrammed) 3 - 1 (unprogrammed) 2 - 1 (unprogrammed) 1 - 1 (unprogrammed) selfprgen (1) 0 self-programming enable 1 (unprogrammed) table 19-4. fuse high byte fuse high byte bit no description default value rstdisbl (1) 7 external reset disable 1 (unprogrammed) dwen (2) 6 debugwire enable 1 (unprogrammed) spien (3) 6 enable serial program and data downloading 0 (programmed, spi prog. enabled) wdton (4) 4 watchdog timer always on 1 (unprogrammed) eesave 3 eeprom memory is preserved through the chip erase 1 (unprogrammed, eeprom not preserved) bodlevel2 (5) 2 brown-out detector trigger level 1 (unprogrammed) bodlevel1 (5) 1 brown-out detector trigger level 1 (unprogrammed) bodlevel0 (5) 0 brown-out detector trigger level 1 (unprogrammed)
161 8006k?avr?10/10 attiny24/44/84 notes: 1. see ?system clock prescaler? on page 30 for details. 2. allows system clock to be output on pin. see ?clock output buffer? on page 30 for details. 3. the default value results in maximum start-up time for the default clock source. see table 6-5 on page 27 for details. 4. the default setting results in internal rc oscillator @ 8.0 mhz. see table 6-4 on page 27 for details. note that fuse bits are locked if lock bit 1 (lb1) is programmed. fuse bits should be pro- grammed before lock bits. the status of fuse bits is not affected by chip erase. fuse bits can also be read by device firmware. see section ?reading lock, fuse and signature data from software? on page 155 . 19.2.1 latching of fuses fuse values are latched when the device enters programming mode and changes to fuse values have no effect until the part leaves programming mode. this does not apply to the eesave fuse which will take effect once it is prog rammed. fuses are also latched on power-up. 19.3 device signature imprint table the device signature imprint table is a dedicated memory area used for storing miscellaneous device information, such as the device signatur e and oscillator calibrat ion data. most of this memory segment is reserved for internal use, as outlined in table 19-6 . notes: 1. see section ?signature bytes? for more information. 2. see section ?calibration byte? for more information. table 19-5. fuse low byte fuse low byte bit no description default value ckdiv8 (1) 7 divide clock by 8 0 (programmed) ckout (2) 6 clock output enable 1 (unprogrammed) sut1 (3) 5 select start-up time 1 (unprogrammed) sut0 (3) 4 select start-up time 0 (programmed) cksel3 (4) 3 select clock source 0 (programmed) cksel2 (4) 2 select clock source 0 (programmed) cksel1 (4) 1 select clock source 1 (unprogrammed) cksel0 (4) 0 select clock source 0 (programmed) table 19-6. contents of device signature imprint table. address high byte 0x00 signature byte 0 (1) 0x01 calibration data for internal oscillator (2) 0x02 signature byte 1 (1) 0x03 reserved for internal use 0x04 signature byte 2 (1) 0x05 ... 0x2a reserved for internal use
162 8006k?avr?10/10 attiny24/44/84 19.3.1 signature bytes all atmel microcontrollers have a three-byte signature code which identifies the device. this code can be read in both serial and high-voltage programming mode, also when the device is locked. signature bytes can also be read by the device firmware. see section ?reading lock, fuse and signature data from software? on page 155 . the three signature bytes reside in a separate address space called the device signature imprint table. the signature data for attiny24/44/84 is given in table 19-7 . 19.3.2 calibration byte the device signature imprint table of attiny24/44/84 contains one byte of calibration data for the internal oscillator, as shown in table 19-6 on page 161 . during reset, this byte is automatically written into the osccal regist er to ensure correct frequen cy of the calibr ated oscillator. calibration bytes can also be read by the device firmware. see section ?reading lock, fuse and signature data from software? on page 155 . 19.4 page size table 19-7. device signature bytes part signature byte 0 signature byte 1 signature byte 0 attiny24 0x1e 0x91 0x0b attiny44 0x1e 0x92 0x07 attiny84 0x1e 0x93 0x0c table 19-8. no. of words in a page and no. of pages in the flash device flash size page size pcword no. of pages pcpage pcmsb at t i n y 2 4 1k words (2k bytes) 16 words pc[3:0] 64 pc[9:4] 9 at t i n y 4 4 2k words (4k bytes) 32 words pc[4:0] 64 pc[10:5] 10 at t i n y 8 4 4k words (8k bytes) 32 words pc[4:0] 128 pc[11:5] 11 table 19-9. no. of words in a page and no. of pages in the eeprom device eeprom size page size pcword no. of pages pcpage eeamsb attiny24 128 bytes 4 bytes eea[1:0] 32 eea[6:2] 6 attiny44 256 bytes 4 bytes eea[1:0] 64 eea[7:2] 7 attiny84 512 bytes 4 bytes eea[1:0] 128 eea[8:2] 8
163 8006k?avr?10/10 attiny24/44/84 19.5 serial programming both the flash and eeprom memo ry arrays can be programmed using the serial spi bus while reset is pulled to gnd. the serial interface consists of pins sck, mosi (input) and miso (out- put). see figure 19-1 below. figure 19-1. serial programming and verify note: if clocked by internal oscillator there is no need to connect a clock source to the clki pin. after reset is set low, the programming enable instruction needs to be executed first before program/erase operations can be executed. note: in table 19-10 above, the pin mapping for spi programming is listed. not all devices use the spi pins dedicated for the internal spi interface. when programming the eeprom, an auto-erase cycle is built into the self-timed programming operation (in the serial mode only) and there is no need to first execute the chip erase table 19-10. pin mapping serial programming symbol pins i/o description mosi pa6 i serial data in miso pa5 o serial data out sck pa4 i serial clock vcc gnd s ck mi s o mo s i re s et +1. 8 - 5.5v
164 8006k?avr?10/10 attiny24/44/84 instruction. the chip erase operation turns the content of every memory location in both the program and eeprom arrays into 0xff. depending on cksel fuses, a valid clock must be present. the minimum low and high periods for the serial clock (sck) input are defined as follows: ? low:> 2 cpu clock cycles for f ck < 12 mhz, 3 cpu clock cycles for f ck >= 12 mhz ? high:> 2 cpu clock cycles for f ck < 12 mhz, 3 cpu clock cycles for f ck >= 12 mhz 19.5.1 serial programming algorithm when writing serial data to the attiny24/44/84, data is clocked on the rising edge of sck. when reading, data is clocked on the falling edge of sck. see figure 20-4 and figure 20-5 for timing details. to program and verify the attiny24/44/84 in the serial programming mode, the following sequence is recommended (see four byte instruction formats in table 19-12 ): 1. power-up sequence: apply power between v cc and gnd while reset and sck are set to ?0?. in some sys- tems, the programmer can not guarantee that sck is held low during power-up. in this case, reset must be given a positive pulse after sck has been set to '0'. the duration of the pulse must be at least t rst (the minimum pulse width on reset pin, see table 20-4 on page 177 ) plus two cpu clock cycles. 2. wait for at least 20 ms and enable serial programming by sending the programming enable serial instruction to pin mosi. 3. the serial programming instructions will no t work if the communic ation is out of syn- chronization. when in sync. the second byte (0x53), will echo back when issuing the third byte of the programming enable instruction. whether the echo is correct or not, all four bytes of the instruction must be transmitted. if the 0x53 did not echo back, give reset a positive pulse and issue a new programming enable command. 4. the flash is programmed one page at a time. the memory page is loaded one byte at a time by supplying the 5 lsb of the address and data together with the load program memory page instruction. to ensure correct loading of the page, the data low byte must be loaded before data high byte is applied for a given address. the program memory page is stored by loading the write program memory page instruction with the 3 msb of the address. if polling (rdy/bsy) is not used, the user must wait at least t wd_flash before issuing the next page. (see table 19-11 on page 165 .) accessing the serial pro- gramming interface before the flash write operation completes can result in incorrect programming. 5. a: the eeprom array is programmed one byte at a time by supplying the address and data together with the appropriate write instruction. an eeprom memory location is first automatically erased before new data is written. if polling (rdy/bsy) is not used, the user must wait at least t wd_eeprom before issuing the next byte. (see table 19-11 on page 165 .) in a chip erased device, no 0xffs in the data file(s) need to be pro- grammed. b: the eeprom array is programmed one page at a time. the memory page is loaded one byte at a time by supplying the 2 lsb of the address and data together with the load eeprom memory page instruction. the eeprom me mory page is stored by loading the write eeprom memory page inst ruction with the 4 msb of the address. when using eeprom page access only by te locations loaded with the load eeprom memory page instruction is altered. the remaining locations remain unchanged. if poll- ing (rdy/bsy) is not used, the used must wait at least t wd_eeprom before issuing the
165 8006k?avr?10/10 attiny24/44/84 next page (see table 19-11 on page 165 ). in a chip erased device, no 0xff in the data file(s) need to be programmed. 6. any memory location can be verified by using the read instruction which returns the content at the selected address at serial output miso. 7. at the end of the programming session, reset can be set high to commence normal operation. 8. power-off sequence (if needed): set reset to ?1?. tu r n v cc power off. 19.5.2 serial programming instruction set the instruction set is described in table 19-12 and figure 19-2 on page 166 . table 19-11. minimum wait delay before writing the next flash or eeprom location symbol minimum wait delay t wd_flash 4.5 ms t wd_eeprom 4.0 ms t wd_erase 9.0 ms t wd_fuse 4.5 ms table 19-12. serial programming instruction set instruction/operation (1) instruction format byte 1 byte 2 byte 3 byte4 programming enable $ac $53 $00 $00 chip erase (program memory/eeprom) $ac $80 $00 $00 poll rdy/bsy $f0 $00 $00 data byte out load instructions load extended address byte $4d $00 extended adr $00 load program memory page, high byte $48 adr msb adr lsb high data byte in load program memory page, low byte $40 adr msb adr lsb low data byte in load eeprom memory page (page access) $c1 $00 adr lsb data byte in read instructions read program memory, high byte $28 adr msb adr lsb high data byte out read program memory, low byte $20 adr msb adr lsb low data byte out read eeprom memory $a0 $00 adr lsb data byte out read lock bits $58 $00 $00 data byte out read signature byte $30 $00 adr lsb data byte out read fuse bits $50 $00 $00 data byte out read fuse high bits $58 $08 $00 data byte out read extended fuse bits $50 $08 $00 data byte out read calibration byte $38 $00 $00 data byte out
166 8006k?avr?10/10 attiny24/44/84 notes: 1. not all instructions are applicable for all parts. 2. a = address 3. bits are programmed ?0?, unprogrammed ?1?. 4. to ensure future compatibility, unused fuses and lock bits should be unprogrammed (?1?) . 5. refer to the correspondig section for fuse and lock bits, calibration and signature bytes and page size. 6. instructions accessing program memory use a word address. this address may be random within the page range. 7. see http://www.atmel.com/avr for application notes regarding programming and programmers. figure 19-2. serial programming instruction example write instructions (6) write program memory page $4c adr msb adr lsb $00 write eeprom memory $c0 $00 adr lsb data byte in write eeprom memory page (page access) $c2 $00 adr lsb $00 write lock bits $ac $e0 $00 data byte in write fuse bits $ac $a0 $00 data byte in write fuse high bits $ac $a8 $00 data byte in write extended fuse bits $ac $a4 $00 data byte in table 19-12. serial programming instruction set (continued) instruction/operation (1) instruction format byte 1 byte 2 byte 3 byte4 byte 1 byte 2 byte 3 byte 4 adr lsb bit 15 b 0 s eri a l progr a mming in s tr u ction progr a m memory/ eeprom memory p a ge 0 p a ge 1 p a ge 2 p a ge n-1 p a ge b u ffer write progr a m memory p a ge/ write eeprom memory p a ge lo a d progr a m memory p a ge (high/low byte)/ lo a d eeprom memory p a ge (p a ge a cce ss ) byte 1 byte 2 byte 3 byte 4 bit 15 b 0 adr msb p a ge off s et p a ge n u m b er ad r m m s s b a a adr r l l s b b
167 8006k?avr?10/10 attiny24/44/84 if the lsb in rdy/bsy data byte out is ?1?, a pr ogramming operation is still pending. wait until this bit returns ?0? before the ne xt instruction is carried out. within the same page, the low data byte must be loaded prior to the high data byte. after data is loaded to the page buf fer, program the eeprom page, see figure 19-2 on page 166 . 19.6 high-voltage serial programming this section describes how to program and verify flash program memory, eeprom data mem- ory, lock bits and fuse bits in the attiny24/44/84. figure 19-3. high-voltage serial programming the minimum period for the serial clock input (sci) during high-voltage serial programming is 220 ns. table 19-13. pin name mapping signal name in high-voltage serial programming mode pin name i/o function sdi pa6 i serial data input sii pa5 i serial instruction input sdo pa4 o serial data output sci pb0 i serial clock input (min. 220ns period) table 19-14. pin values used to enter programming mode pin symbol value pa0 prog_enable[0] 0 pa1 prog_enable[1] 0 pa2 prog_enable[2] 0 vcc gnd sdo sii sdi (reset) +4.5 - 5.5v pa 6 pa 5 pa 4 pb3 +11.5 - 12.5v pb0 sci pa2:0
168 8006k?avr?10/10 attiny24/44/84 19.7 high-voltage serial programming algorithm to program and verify the attiny24/44/84 in the high-voltage serial programming mode, the fol- lowing sequence is recommended (see instruction formats in table 19-16 on page 171 ): 19.7.1 enter high-voltage serial programming mode the following algorithm puts the device in high-voltage serial programming mode: 1. set prog_enable pins listed in table 19-14 on page 167 to ?000?, reset pin and v cc to 0v. 2. apply 4.5 - 5.5v between v cc and gnd. ensure that v cc reaches at least 1.8v within the next 20 s. 3. wait 20 - 60 s, and apply 11.5 - 12.5v to reset. 4. keep the prog_enable pins unchanged for at least 10 s after the high-voltage has been applied to ensure the prog_enable signature has been latched. 5. release the prog_enable[2] pin after t hvrst has elapsed. 6. wait at least 300 s before giving any serial instructions on sdi/sii. 7. exit programming mode by power the device down or by bringing reset pin to 0v. if the rise time of the v cc is unable to fulfill the requiremen ts listed above, th e following alterna- tive algorithm can be used: 1. set prog_enable pins listed in table 19-14 on page 167 to ?000?, reset pin and v cc to 0v. 2. apply 4.5 - 5.5v between v cc and gnd. 3. monitor v cc , and as soon as v cc reaches 0.9 - 1.1v, apply 11.5 - 12.5v to reset. 4. keep the prog_enable pins unchanged for at least 10 s after the high-voltage has been applied to ensure the prog_enable signature has been latched. 5. release the prog_enable[2] pin to avoid drive contention on the prog_enable[2]/sdo pin. 6. wait until v cc actually reaches 4.5 - 5.5v before giving any serial instructions on sdi/sii. 7. exit programming mode by power the device down or by bringing reset pin to 0v. table 19-15. high-voltage reset characteristics supply voltage reset pin high-voltage threshold minimum high-voltage period for latching prog_enable v cc v hvrst t hvrst 4.5v 11.5v 100 ns 5.5v 11.5v 100 ns
169 8006k?avr?10/10 attiny24/44/84 19.7.2 considerations for efficient programming the loaded command and address are retained in the device during programming. for efficient programming, the following should be considered. ? the command needs only be loaded once when writing or reading multiple memory locations. ? skip writing the data value 0xff that is the contents of the entire eeprom (unless the eesave fuse is programmed) and flash after a chip erase. ? address high byte needs only be loaded before programming or reading a new 256 word window in flash or 256 byte eeprom. this consideration also applies to signature bytes reading. 19.7.3 chip erase the chip erase will erase the flash and eeprom (1) memories plus lock bits. the lock bits are not reset until the program memory has been completely erased. the fuse bits are not changed. a chip erase must be performed before the flash and/or eeprom are re- programmed. 1. load command ?chip erase? (see table 19-16 on page 171 ). 2. wait after instr. 3 until sdo goes high for the ?chip erase? cycle to finish. 3. load command ?no operation?. note: 1. the eeprom memory is preserved duri ng chip erase if the eesave fuse is programmed. 19.7.4 programming the flash the flash is organized in pages, see ?page size? on page 162 . when programming the flash, the program data is latched into a page buffer. this allows one page of program data to be pro- grammed simultaneously. the following procedure describes how to program the entire flash memory: 1. load command ?write flash? (see table 19-16 on page 171 ). 2. load flash page buffer. 3. load flash high address and program page. wait after instr. 3 until sdo goes high for the ?page programming? cycle to finish. 4. repeat 2 through 3 until the entire flash is programmed or until all data has been programmed. 5. end page programming by loading command ?no operation?. when writing or reading serial data to the atti ny24/44/84, data is clocked on the rising edge of the serial clock, see figure 20-6 on page 184 , figure 19-3 on page 167 and table 20-13 on page 184 for details.
170 8006k?avr?10/10 attiny24/44/84 figure 19-4. addressing the flash which is organized in pages figure 19-5. high-voltage serial programming waveforms 19.7.5 programming the eeprom the eeprom is organized in pages, see table 20-12 on page 183 . when programming the eeprom, the data is latc hed into a page buffer. this allo ws one page of data to be pro- grammed simultaneously. the programming algorithm for the eeprom data memory is as follows (refer to table 19-16 on page 171 ): 1. load command ?write eeprom?. 2. load eeprom page buffer. 3. program eeprom page. wait after instr. 2 until sdo goes high for the ?page program- ming? cycle to finish. 4. repeat 2 through 3 until the entire eeprom is progra mmed or until all data has been programmed. 5. end page programming by loading command ?no operation?. program memory word address within a page page address within the flash instruction word pag e pcword[pagemsb:0]: 00 01 02 pageend pag e pcword pcpage pcmsb pagemsb program counter msb msb msb lsb lsb lsb 012345678910 sdi pb0 sii pb1 sdo pb2 sci pb3
171 8006k?avr?10/10 attiny24/44/84 19.7.6 reading the flash the algorithm for reading the flash memory is as follows (refer to table 19-16 on page 171 ): 1. load command "read flash". 2. read flash low and high bytes. the contents at the selected address are available at serial output sdo. 19.7.7 reading the eeprom the algorithm for reading the eeprom memory is as follows (refer to table 19-16 on page 171 ): 1. load command ?read eeprom?. 2. read eeprom byte. the contents at the selected address are available at serial out- put sdo. 19.7.8 programming and reading the fuse and lock bits the algorithms for programming and reading the fuse low/high bits and lock bits are shown in table 19-16 on page 171 . 19.7.9 reading the signature bytes and calibration byte the algorithms for reading the signature bytes and calibration byte are shown in table 19-16 on page 171 . 19.7.10 power-off sequence set sci to ?0?. set reset to ?1?. turn v cc power off. table 19-16. high-voltage serial programming instruction set for attiny24/44/84 instruction instruction format operation remarks instr.1/5 instr.2/6 instr.3/7 instr.4 chip erase sdi sii sdo 0_1000_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx wait after instr.3 until sdo goes high for the chip erase cycle to finish. load ?write flash? command sdi sii sdo 0_0001_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx enter flash programming code. load flash page buffer sdi sii sdo 0_ bbbb _ bbbb _00 0_0000_1100_00 x_xxxx_xxxx_xx 0_ eeee _ eeee _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1101_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx repeat after instr. 1 - 7until the entire page buffer is filled or until all data within the page is filled. (2) sdi sii sdo 0_ dddd _ dddd _00 0_0011_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1101_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1100_00 x_xxxx_xxxx_xx instr 5-7. load flash high address and program page sdi sii sdo 0_0000_000 a _00 0_0001_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx wait after instr 3 until sdo goes high. repeat instr. 2 - 3 for each loaded flash page until the entire flash or all data is programmed. repeat instr. 1 for a new 256 byte page. (2)
172 8006k?avr?10/10 attiny24/44/84 load ?read flash? command sdi sii sdo 0_0000_0010_00 0_0100_1100_00 x_xxxx_xxxx_xx enter flash read mode. read flash low and high bytes sdi sii sdo 0_ bbbb _ bbbb _00 0_0000_1100_00 x_xxxx_xxxx_xx 0_0000_000 a _00 0_0001_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 q _ qqqq _ qqq x_xx repeat instr. 1, 3 - 6 for each new address. repeat instr. 2 for a new 256 byte page. sdi sii sdo 0_0000_0000_00 0_0111_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1100_00 p _ pppp _ ppp x_xx instr 5 - 6. load ?write eeprom? command sdi sii sdo 0_0001_0001_00 0_0100_1100_00 x_xxxx_xxxx_xx enter eeprom programming mode. load eeprom page buffer sdi sii sdo 0_ bbbb _ bbbb _00 0_0000_1100_00 x_xxxx_xxxx_xx 0_ aaaa _ aaaa _00 0_0001_1100_00 x_xxxx_xxxx_xx 0_ eeee _ eeee _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1101_00 x_xxxx_xxxx_xx repeat instr. 1 - 5 until the entire page buffer is filled or until all data within the page is filled. (3) sdi sii sdo 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx program eeprom page sdi sii sdo 0_0000_0000_00 0_0110_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx wait after instr. 2 until sdo goes high. repeat instr. 1 - 2 for each loaded eeprom page until the entire eeprom or all data is programmed. write eeprom byte sdi sii sdo 0_ bbbb _ bbbb _00 0_0000_1100_00 x_xxxx_xxxx_xx 0_ aaaa _ aaaa _00 0_0001_1100_00 x_xxxx_xxxx_xx 0_ eeee _ eeee _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1101_00 x_xxxx_xxxx_xx repeat instr. 1 - 6 for each new address. wait after instr. 6 until sdo goes high. (4) sdi sii sdo 0_0000_0000_00 0_0110_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx instr. 5-6 load ?read eeprom? command sdi sii sdo 0_0000_0011_00 0_0100_1100_00 x_xxxx_xxxx_xx enter eeprom read mode. read eeprom byte sdi sii sdo 0_ bbbb _ bbbb _00 0_0000_1100_00 x_xxxx_xxxx_xx 0_ aaaa _ aaaa _00 0_0001_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 q _ qqqq _ qqq 0_00 repeat instr. 1, 3 - 4 for each new address. repeat instr. 2 for a new 256 byte page. write fuse low bits sdi sii sdo 0_0100_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_ a987 _ 6543 _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx wait after instr. 4 until sdo goes high. write a - 3 = ?0? to program the fuse bit. write fuse high bits sdi sii sdo 0_0100_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_ ihgf _ edcb _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1100_00 x_xxxx_xxxx_xx wait after instr. 4 until sdo goes high. write f - b = ?0? to program the fuse bit. write fuse extended bits sdi sii sdo 0_0100_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_000 j _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_0110_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1110_00 x_xxxx_xxxx_xx wait after instr. 4 until sdo goes high. write j = ?0? to program the fuse bit. table 19-16. high-voltage serial programming instruction set for attiny24/44/84 (continued) instruction instruction format operation remarks instr.1/5 instr.2/6 instr.3/7 instr.4
173 8006k?avr?10/10 attiny24/44/84 notes: 1. a = address high bits, b = address low bits, d = data in high bits, e = data in low bits, p = data out high bits, q = data out low bits, x = don?t care, 1 = lock bit1, 2 = lock bit2, 3 = cksel0 fuse, 4 = cksel1 fuse, 5 = cksel2 fuse, 6 = cksel3 fuse, 7 = sut0 fuse, 8 = sut1 fuse, 9 = ckout fuse, a = ckdiv8 fuse, b = bodlevel0 fuse, c = bodlevel1 fuse, d = bodlevel2 fuse, e = eesave fuse, f = wdton fuse, g = spien fuse, h = dwen fuse, i = rstdisbl fuse, j = selfprgen 2. for page sizes less than 256 words, parts of the address (bbbb_bbbb) will be parts of the page address. 3. for page sizes less than 256 bytes, parts of the address (bbbb_bbbb) will be parts of the page address. 4. the eeprom is written page-wise. but onl y the bytes that are loaded into the page are actually written to the eeprom. page-wise eeprom access is more efficient when multiple byte s are to be written to the same page. note that auto-erase of eeprom is not available in high-voltage serial programmi ng, only in spi programming. write lock bits sdi sii sdo 0_0010_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_00 21 _00 0_0010_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_0100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_xxxx_xx wait after instr. 4 until sdo goes high. write 2 - 1 = ?0? to program the lock bit. read fuse low bits sdi sii sdo 0_0000_0100_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 a _ 9876 _ 543 x_xx reading a - 3 = ?0? means the fuse bit is programmed. read fuse high bits sdi sii sdo 0_0000_0100_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1010_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1100_00 i _ hgfe _ dcb x_xx reading f - b = ?0? means the fuse bit is programmed. read fuse extended bits sdi sii sdo 0_0000_0100_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1010_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1110_00 x_xxxx_xxjx_xx reading j = ?0? means the fuse bit is programmed. read lock bits sdi sii sdo 0_0000_0100_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 x_xxxx_x 21 x_xx reading 2, 1 = ?0? means the lock bit is programmed. read signature bytes sdi sii sdo 0_0000_1000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_00 bb _00 0_0000_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0110_1100_00 q _ qqqq _ qqq x_xx repeats instr 2 4 for each signature byte address. read calibration byte sdi sii sdo 0_0000_1000_00 0_0100_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0000_1100_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1000_00 x_xxxx_xxxx_xx 0_0000_0000_00 0_0111_1100_00 p _ pppp _ ppp x_xx load ?no operation? command sdi sii sdo 0_0000_0000_00 0_0100_1100_00 x_xxxx_xxxx_xx table 19-16. high-voltage serial programming instruction set for attiny24/44/84 (continued) instruction instruction format operation remarks instr.1/5 instr.2/6 instr.3/7 instr.4
174 8006k?avr?10/10 attiny24/44/84 20. electrical characteristics 20.1 absolute maximum ratings* 20.2 dc characteristics operating temperature.................................. -55 c to +125 c *notice: stresses beyond those listed under ?absolute maximum ratings? may cause permanent dam- age to the device. this is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of th is specification is not implied. exposure to absolute maximum rating conditions for extended periods may affect device reliability. storage temperature ..................................... -65 c to +150 c voltage on any pin except reset with respect to ground ................................-0.5v to v cc +0.5v voltage on reset with respect to ground......-0.5v to +13.0v maximum operating voltage ............................................ 6.0v dc current per i/o pin ............................................... 40.0 ma dc current v cc and gnd pins ................................ 200.0 ma table 20-1. dc characteristics. t a = -40 c to +85 c symbol parameter condition min typ (1) max units v il input low voltage v cc = 1.8 - 2.4v v cc = 2.4 - 5.5v -0.5 0.2v cc (3) 0.3v cc (3) v v ih input high-voltage except reset pin v cc = 1.8 - 2.4v v cc = 2.4 - 5.5v 0.7v cc (2) 0.6v cc (2) v cc +0.5 v v ih1 input high-voltage reset pin v cc = 1.8v to 5.5v 0.9v cc (2) v cc +0.5 v v ol output low voltage (4) except reset pin (6) i ol = 10 ma, v cc = 5v i ol = 5 ma, v cc = 3v 0.6 0.5 v v v oh output high-voltage (5) except reset pin (6) i oh = -10 ma, v cc = 5v i oh = -5 ma, v cc = 3v 4.3 2.5 v v i lil input leakage current i/o pin v cc = 5.5v, pin low (absolute value) < 0.05 1 a i lih input leakage current i/o pin v cc = 5.5v, pin high (absolute value) < 0.05 1 a r rst reset pull-up resistor v cc = 5.5v, input low 30 60 k r pu i/o pin pull-up resistor v cc = 5.5v, input low 20 50 k
175 8006k?avr?10/10 attiny24/44/84 notes: 1. typical values at +25 c. 2. ?min? means the lowest value where t he pin is guaranteed to be read as high. 3. ?max? means the highest value where the pin is guaranteed to be read as low. 4. although each i/o port can sink more than the test conditions (10 ma at v cc = 5v, 5 ma at v cc = 3v) under steady state conditions (non-transient), the sum of all i ol (for all ports) should not exceed 60 ma. if i ol exceeds the test conditions, v ol may exceed the related specification. pins are not guarante ed to sink current greater th an the listed test condition. 5. although each i/o port can source more than the test conditions (10 ma at v cc = 5v, 5 ma at v cc = 3v) under steady state conditions (non-transient), the sum of all i oh (for all ports) should not exceed 60 ma. if i oh exceeds the test condition, v oh may exceed the related specification. pins are not guaranteed to source current greater than the listed test condition. 6. the reset pin must tolerate high voltages when entering and operating in programming modes and, as a consequence, has a weak drive strength as compared to regular i/o pins. see figure 21-24 , figure 21-25 , figure 21-26 , and figure 21-27 (starting on page 198 ). 7. values are with external clock using methods described in ?minimizing power consumption? on page 35 . power reduction is enabled (prr = 0xff) and there is no i/o drive. 8. bod disabled. 20.3 speed the maximum operating frequency of the device depends on v cc. as shown in figure 20-1 and figure 20-2 , the maximum frequency vs. v cc relationship is linear between 1.8v < v cc < 2.7v and between 2.7v < v cc < 4.5v. figure 20-1. maximum frequency vs. v cc (attiny24v/44v/84v) i cc power supply current (7) active 1mhz, v cc = 2v 0.33 0.8 ma active 4mhz, v cc = 3v 1.6 2.5 ma active 8mhz, v cc = 5v 5 9 ma idle 1mhz, v cc = 2v 0.11 0.4 ma idle 4mhz, v cc = 3v 0.4 1.0 ma idle 8mhz, v cc = 5v 1.5 3.5 ma power-down mode (8) wdt enabled, v cc = 3v 4.5 10 a wdt disabled, v cc = 3v 0.15 2 a table 20-1. dc characteristics. t a = -40 c to +85 c (continued) symbol parameter condition min typ (1) max units 10 mhz 4 mhz 1.8v 2.7v 5.5v safe operating area
176 8006k?avr?10/10 attiny24/44/84 figure 20-2. maximum frequency vs. v cc (attiny24/44/84) 20.4 clock characteristics 20.4.1 accuracy of calibrated internal rc oscillator it is possible to manua lly calibrate the internal oscillator to be more accu rate than def ault factory calibration. note that the osc illator frequency depend s on temperat ure and voltage. voltage and temperature characteristics can be found in figure 21-40 on page 206 and figure 21-41 on page 206 . notes: 1. accuracy of oscillator frequency at calibra tion point (fixed temperature and fixed voltage). 2. voltage range for attiny24v/44v/84v. 3. voltage range for attiny24/44/84. 20 mhz 10 mhz 2.7v 4.5v 5.5v safe operating area table 20-2. calibration accuracy of internal rc oscillator calibration method target frequency v cc temperature accuracy at given voltage & temperature (1) factory calibration 8.0 mhz 3v 25 c10% user calibration fixed frequency within: 7.3 ? 8.1 mhz fixed voltage within: 1.8 ? 5.5v (2) 2.7 ? 5.5v (3) fixed temperature within: -40 c to +85 c 1%
177 8006k?avr?10/10 attiny24/44/84 20.4.2 external clock drive figure 20-3. external clock drive waveform 20.5 system and reset characteristics note: 1. values are guidelines only. v il1 v ih1 table 20-3. external clock drive characteristics symbol parameter v cc = 1.8 - 5.5v v cc = 2.7 - 5.5v v cc = 4.5 - 5.5v units min. max. min. max. min. max. 1/t clcl clock frequency 0 4 0 10 0 20 mhz t clcl clock period 250 100 50 ns t chcx high time 100 40 20 ns t clcx low time 100 40 20 ns t clch rise time 2.0 1.6 0.5 s t chcl fall time 2.0 1.6 0.5 s t clcl change in period from one clock cycle to the next 2 2 2 % table 20-4. reset, brown-out, and internal voltage characteristics symbol parameter condition min (1) typ (1) max (1) units v rst reset pin threshold voltage 0.2 v cc 0.9v cc v t rst minimum pulse width on reset pin v cc = 1.8v v cc = 3v v cc = 5v 2000 700 400 ns v hyst brown-out detector hysteresis 50 mv t bod min pulse width on brown-out reset 2s v bg internal bandgap reference voltage v cc = 5v t a = 25c 1.0 1.1 1.2 v t bg internal bandgap reference start-up time v cc = 5v t a = 25c 40 70 s i bg internal bandgap reference current consumption v cc = 5v t a = 25c 15 a
178 8006k?avr?10/10 attiny24/44/84 two versions of power-on reset have been implemented, as follows. 20.5.1 standard power-on reset this implementation of power-on reset existed in early versions of attiny24/44/84. the table below describes the characteristics of this power-on reset and it is valid for the following devices, only: ? attiny24, revision d, and older ? attiny44, revision c, and older ? attiny84, revision a note: revisions are marked on the package (packages 14p3 and 14s1: bottom, package 20m1: top) notes: 1. values are guidelines only. 2. threshold where device is released from reset when voltage is rising. 3. the power-on reset will not work unless the supply voltage has been below v poa . 20.5.2 enhanced power-on reset this implementation of power-on reset exists in newer versions of attiny24/44/84. the table below describes the characteristics of this power-on reset and it is valid for the following devices, only: ? attiny24, revision e, and newer ? attiny44, revision d, and newer ? attiny84, revision b, and newer notes: 1. values are guidelines only. 2. threshold where device is released from reset when voltage is rising. 3. the power-on reset will not work unless the supply voltage has been below v poa . table 20-5. characteristics of standard power-on reset. t a = -40 to +85 c symbol parameter min (1) typ (1) max (1) units v por release threshold of power-on reset (2) 0.7 1.0 1.4 v v poa activation threshold of power-on reset (3) 0.05 0.9 1.3 v sr on power-on slope rate 0.01 4.5 v/ms table 20-6. characteristics of enhanced power-on reset. t a = -40 to +85 c symbol parameter min (1) typ (1) max (1) units v por release threshold of power-on reset (2) 1.1 1.4 1.6 v v poa activation threshold of power-on reset (3) 0.6 1.3 1.6 v sr on power-on slope rate 0.01 v/ms
179 8006k?avr?10/10 attiny24/44/84 20.5.3 brown-out detection note: 1. v bot may be below nominal minimum operating voltage for some devices. for devices where this is the case, the device is tested down to v cc = v bot during the production test. this guar- antees that a brown-out reset will occur before v cc drops to a voltage where correct operation of the microcontroller is no longer guaranteed. 20.6 analog comparat or characteristics note: all parameters are based on simulation results. table 20-7. v bot vs. bodlevel fuse coding bodlevel[2:0] fuses min (1) typ (1) max (1) units 111 bod disabled 110 1.7 1.8 2.0 v 101 2.5 2.7 2.9 100 4.1 4.3 4.5 0xx reserved table 20-8. analog comparator characteristics, t a = -40 c to +85 c symbol parameter condi tion min typ max units v aio input offset voltage v cc = 5v, v in = v cc / 2 < 10 40 mv i lac input leakage current v cc = 5v, v in = v cc / 2 -50 50 na t apd analog propagation delay (from saturation to slight overdrive) v cc = 2.7v 750 ns v cc = 4.0v 500 analog propagation delay (large step change) v cc = 2.7v 100 v cc = 4.0v 75 t dpd digital propagation delay v cc = 1.8 - 5.5v 1 2 clk
180 8006k?avr?10/10 attiny24/44/84 20.7 adc characteristics note: 1. values are guidelines only. table 20-9. adc characteristics, single ended channels. t = -40 c to +85 c symbol parameter condition min (1) typ (1) max (1) units resolution 10 bits absolute accuracy (including inl, dnl, and quantization, gain and offset errors) v ref = 4v, v cc = 4v, adc clock = 200 khz 2.0 lsb v ref = 4v, v cc = 4v, adc clock = 1 mhz 2.5 lsb v ref = 4v, v cc = 4v, adc clock = 200 khz noise reduction mode 1.5 lsb v ref = 4v, v cc = 4v, adc clock = 1 mhz noise reduction mode 2.0 lsb integral non-linearity (inl) (accuracy after offset and gain calibration) v ref = 4v, v cc = 4v, adc clock = 200 khz 1.0 lsb differential non-linearity (dnl) v ref = 4v, v cc = 4v, adc clock = 200 khz 0.5 lsb gain error v ref = 4v, v cc = 4v, adc clock = 200 khz 2.0 lsb offset error v ref = 4v, v cc = 4v, adc clock = 200 khz 1.5 lsb conversion time free running conversion 14 280 s clock frequency 50 1000 khz v in input voltage gnd v ref v input bandwidth 38.4 khz a ref external voltage reference 2.0 v cc v v int internal voltage reference 1.0 1.1 1.2 v r ref reference input resistance 32 k r ain analog input resistance 100 m adc conversion output 0 1023 lsb
181 8006k?avr?10/10 attiny24/44/84 note: 1. values are guidelines only. table 20-10. adc characteristics, differential channels (unipolar mode), t a = -40 c to +85 c symbol parameter condition min (1) typ (1) max (1) units resolution gain = 1x 10 bits gain = 20x 10 bits absolute accuracy (including inl, dnl, and quantization, gain and offset errors) gain = 1x v ref = 4v, v cc = 5v adc clock = 50 - 200 khz 10.0 lsb gain = 20x v ref = 4v, v cc = 5v adc clock = 50 - 200 khz 20.0 lsb integral non-linearity (inl) (accuracy after offset and gain calibration) gain = 1x v ref = 4v, v cc = 5v adc clock = 50 - 200 khz 4.0 lsb gain = 20x v ref = 4v, v cc = 5v adc clock = 50 - 200 khz 10.0 lsb gain error gain = 1x 10.0 lsb gain = 20x 15.0 lsb offset error gain = 1x v ref = 4v, v cc = 5v adc clock = 50 - 200 khz 3.0 lsb gain = 20x v ref = 4v, v cc = 5v adc clock = 50 - 200 khz 4.0 lsb conversion time free running conversion 70 280 s clock frequency 50 200 khz v in input voltage gnd v cc v v diff input differential voltage v ref /gain v input bandwidth 4khz a ref external reference voltage 2.0 v cc - 1.0 v v int internal voltage reference 1.0 1.1 1.2 v r ref reference input resistance 32 k r ain analog input resistance 100 m adc conversion output 0 1023 lsb
182 8006k?avr?10/10 attiny24/44/84 note: 1. values are guidelines only. table 20-11. adc characteristics, differential channels (bipolar mode), t a = -40 c to +85 c symbol parameter condition min (1) typ (1) max (1) units resolution gain = 1x 10 bits gain = 20x 10 bits absolute accuracy (including inl, dnl, and quantization, gain and offset errors) gain = 1x v ref = 4v, v cc = 5v adc clock = 50 - 200 khz 8.0 lsb gain = 20x v ref = 4v, v cc = 5v adc clock = 50 - 200 khz 8.0 lsb integral non-linearity (inl) (accuracy after offset and gain calibration) gain = 1x v ref = 4v, v cc = 5v adc clock = 50 - 200 khz 4.0 lsb gain = 20x v ref = 4v, v cc = 5v adc clock = 50 - 200 khz 5.0 lsb gain error gain = 1x 4.0 lsb gain = 20x 5.0 lsb offset error gain = 1x v ref = 4v, v cc = 5v adc clock = 50 - 200 khz 3.0 lsb gain = 20x v ref = 4v, v cc = 5v adc clock = 50 - 200 khz 4.0 lsb conversion time free running conversion 70 280 s clock frequency 50 200 khz v in input voltage gnd v cc v v diff input differential voltage v ref /gain v input bandwidth 4khz a ref external reference voltage 2.0 v cc - 1.0 v v int internal voltage reference 1.0 1.1 1.2 v r ref reference input resistance 32 k r ain analog input resistance 100 m adc conversion output -512 511 lsb
183 8006k?avr?10/10 attiny24/44/84 20.8 serial programming characteristics figure 20-4. serial programming timing figure 20-5. serial programming waveform note: 1. 2 t clcl for f ck < 12 mhz, 3 t clcl for f ck >= 12 mhz table 20-12. serial programming characteristics, t a = -40 c to +85 c, v cc = 1.8 - 5.5v (unless otherwise noted) symbol parameter min typ max units 1/t clcl oscillator frequency (attiny24/44/84v) 0 4 mhz t clcl oscillator period (attiny24/44/84v) 250 ns 1/t clcl oscillator freq. (attiny24/44/84, v cc = 4.5v - 5.5v) 0 20 mhz t clcl oscillator period (attiny24/44/84, v cc = 4.5v - 5.5v) 50 ns t shsl sck pulse width high 2 t clcl (1) ns t slsh sck pulse width low 2 t clcl (1) ns t ovsh mosi setup to sck high t clcl ns t shox mosi hold after sck high 2 t clcl ns mo s i mi s o s ck t ov s h t s h s l t s l s h t s hox m s b m s b l s b l s b s erial clock input ( s ck) s erial data input (mo s i) (mi s o) s ample s erial data output
184 8006k?avr?10/10 attiny24/44/84 20.9 high-voltage serial programming characteristics figure 20-6. high-voltage serial programming timing table 20-13. high-voltage serial programming characteristics t a = 25 c, v cc = 5v (unless otherwise noted) symbol parameter min typ max units t shsl sci (pb0) pulse width high 125 ns t slsh sci (pb0) pulse width low 125 ns t ivsh sdi (pa6), sii (pb1) valid to sci (pb0) high 50 ns t shix sdi (pa6), sii (pb1) hold after sci (pb0) high 50 ns t shov sci (pb0) high to sdo (pa4) valid 16 ns t wlwh_pfb wait after instr. 3 for write fuse bits 2.5 ms sdi (pa6), sii (pa5) sdo (pa4) sci (pb0) t ivsh t shsl t slsh t shix t shov
185 8006k?avr?10/10 attiny24/44/84 21. typical characteristics the data contained in this section is largely based on simulations and characterization of similar devices in the same process and design methods. thus, the data should be treated as indica- tions of how the part will behave. the following charts show typical behavior. t hese figures are not tested during manufacturing. during characterisation devices are operated at fr equencies higher than test limits but they are not guaranteed to function properly at frequencies higher than the ordering code indicates. all current consumption measurements are performed with all i/o pins configured as inputs and with internal pull-ups enabled. current consumption is a function of several factors such as oper- ating voltage, operating frequency, loading of i/o pins, switching rate of i/o pins, code executed and ambient temperature. the dominating factors are operating voltage and frequency. a sine wave generator with rail-to-rail output is used as clock source but current consumption in power-down mode is independent of clock selection. the difference between current consump- tion in power-down mode with watchdog timer enabled and power-down mode with watchdog timer disabled represents the differential current drawn by the watchdog timer. the current drawn from pins with a capacitive lo ad may be estimated (for one pin) as follows: where v cc = operating voltage, c l = load capacitance and f sw = average switching frequency of i/o pin. 21.1 supply current of i/o modules the tables and formulas below can be used to calculate the additional current consumption for the different i/o modules in active and idle mode. the enabling or disabling of the i/o modules is controlled by the powe r reduction register. see ?power reduction register? on page 35 for details. table 21-2 below can be used for calculating typical current consumption for other supply volt- ages and frequencies than those mentioned in the table 21-1 above. i cp v cc c l f sw table 21-1. additional current consumption for the different i/o modules (absolute values) prr bit typical numbers v cc = 2v, f = 1mhz v cc = 3v, f = 4mhz v cc = 5v, f = 8mhz prtim1 5.1 a 31.0 a 118.2 a prtim0 6.6 a 40.0 a 153.0 a prusi 3.7 a 23.1 a 92.2 a pradc 29.6 a 88.3 a 333.3 a
186 8006k?avr?10/10 attiny24/44/84 21.1.1 example calculate the expected current consumption in idle mode with usi, timer0, and adc enabled at v cc = 2.0v and f = 1mhz. from table 21-2 on page 186 , third column, we se e that we need to add 6.1% for the usi, 10.4% for timer0, and 28.8% for the adc. reading from figure 21-6 on page 189 , we find that current consumption in idle mode at 2v and 1mhz is about 0.04ma. the total current consumption in idle mode with usi, timer0, and adc enabled is therefore: 21.2 active supply current figure 21-1. active supply current vs. low frequency (0.1 - 1.0 mhz) table 21-2. additional current consumption (percentage) in active and idle mode prr bit current consumption additional to active mode with external clock (see figure 21-1 and figure 21-2 ) current consumption additional to idle mode with external clock (see figure 21-6 and figure 21-7 ) prtim1 1.8 % 8.0 % prtim0 2.3 % 10.4 % prusi 1.4 % 6.1 % pradc 6.7 % 28.8 % i cctot 0,04 ma 1 0,061 0,104 0,288 +++ () 0,06 ma ? active supply current vs. low frequency (prr=0xff) 5.5 v 5.0 v 4.5 v 4.0 v 3.3 v 2.7 v 1.8 v 0 0.2 0.4 0.6 0.8 1 1.2 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 fre q uency (mhz) i cc (ma)
187 8006k?avr?10/10 attiny24/44/84 figure 21-2. active supply current vs. frequency (1 - 20 mhz) figure 21-3. active supply current vs. v cc (internal rc o scillator, 8 mhz) active supply current vs. frequency (prr=0xff) 0 2 4 6 8 10 12 14 0 2 4 6 8 101214161820 fre q uency (mhz) i cc (ma) 5.5 v 5.0 v 4.5 v 4.0 v 3.3 v 2.7 v 1.8 v active supply current vs. supply voltage internal rc oscillator, 8 mhz 85 c 25 c -40 c 0 1 2 3 4 5 6 1.522.533.544.555.5 v cc (v) i cc (ma)
188 8006k?avr?10/10 attiny24/44/84 figure 21-4. active supply current vs. v cc (internal rc o scillator, 1 mhz) figure 21-5. active supply current vs. v cc (internal rc o scillator, 128 khz) active supply current vs. v cc internal rc oscillator, 1 mhz 85 c 25 c -40 c 0 0.2 0.4 0.6 0.8 1 1.2 1.522.533.544.555.5 v cc (v) i cc (ma) active supply current vs. v cc internal rc oscillator, 128 khz 85 c 25 c -40 c 0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 1.5 2 2.5 3 3.5 4 4.5 5 5.5 v cc (v) i cc (ma)
189 8006k?avr?10/10 attiny24/44/84 21.3 idle supply current figure 21-6. idle supply current vs. low frequency (0.1 - 1.0 mhz) figure 21-7. idle supply current vs. frequency (1 - 20 mhz) idle supply current vs. low frequency (prr=0xff) 5.5 v 5.0 v 4.5 v 4.0 v 3.3 v 2.7 v 1.8 v 0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 fre q uency (mhz) i cc (ma) idle supply current vs. frequency (prr=0xff) 5.5 v 5.0 v 4.5 v 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 02468101214161820 fre q uency (mhz) i cc (ma) 3.3 v 2.7 v 4.0 v 1.8 v
190 8006k?avr?10/10 attiny24/44/84 figure 21-8. idle supply current vs. v cc (internal rc o scillator, 8 mhz) figure 21-9. idle supply current vs. v cc (internal rc o scillator, 1 mhz) idle supply current vs. v cc internal rc oscillator, 8 mhz 85 c 25 c -40 c 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 1.5 2 2.5 3 3.5 4 4.5 5 5.5 vcc (v) i cc (ma) idle supply current vs. v cc internal rc oscillator, 1 mhz 85 c 25 c -40 c 0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 1.5 2 2.5 3 3.5 4 4.5 5 5.5 v cc (v) i cc (ma)
191 8006k?avr?10/10 attiny24/44/84 figure 21-10. idle supply current vs. v cc (internal rc o scillator, 128 khz) 21.4 power-down supply current figure 21-11. power-down supply current vs. v cc (watchdog timer disabled) idle supply current vs. v cc internal rc oscillator, 128 khz 85 c 25 c -40 c 0 0.005 0.01 0.015 0.02 0.025 0.03 1.5 2 2.5 3 3.5 4 4.5 5 5.5 v cc (v) i cc (ma) power-down s upply current v s . v cc watchdog timer di s abled 8 5 c 25 c -40 c 0 0.1 0.2 0. 3 0.4 0.5 0.6 0.7 1.5 2 2.5 33 .5 4 4.5 5 5.5 v cc (v) i cc ( u a)
192 8006k?avr?10/10 attiny24/44/84 figure 21-12. power-down supply current vs. v cc (watchdog timer enabled) 21.5 standby supply current figure 21-13. standby supply current vs. v cc (4 mhz external crystal, watchdog timer disabled) power-down s upply current v s . v cc watchdog timer enabled 8 5 c 25 c -40 c 0 1 2 3 4 5 6 7 8 9 10 1.5 2 2.5 33 .5 4 4.5 5 5.5 v cc (v) i cc ( u a) s tandby s upply current v s . v cc 4 mhz external cry s tal, watchdog timer di s abled 8 5 ?c 25 ?c -40 ?c 0 0.02 0.04 0.06 0.0 8 0.1 0.12 0.14 1.5 2 2.5 33 .5 4 4.5 5 5.5 v cc (v) i cc (m a)
193 8006k?avr?10/10 attiny24/44/84 21.6 pin pull-up figure 21-14. i/o pin pull-up resistor current vs. input voltage (v cc = 1.8v) figure 21-15. i/o pin pull-up resistor current vs. input voltage (v cc = 2.7v) i/o pin pull-up re s i s tor current v s . input voltage v cc = 1. 8 v 8 5 ?c 25 ?c -40 ?c 0 5 10 15 20 25 3 0 3 5 40 45 50 0 0.2 0.4 0.6 0. 8 1 1.2 1.4 1.6 1. 8 2 v op (v) i op ( u a) i/o pin pull-up re s i s tor current v s . input voltage v cc = 2.7v 8 5 ?c 25 ?c -40 ?c 0 10 20 3 0 40 50 60 70 8 0 0 0.5 1 1.5 2 2.5 3 v op (v) i op ( u a)
194 8006k?avr?10/10 attiny24/44/84 figure 21-16. i/o pin pull-up resistor current vs. input voltage (v cc = 5v) figure 21-17. reset pull-up resistor curr ent vs. reset pin voltage (v cc = 1.8v) i/o pin pull-up re s i s tor current v s . input voltage v cc = 5v 8 5 ?c 25 ?c -40 ?c 0 20 40 60 8 0 100 120 140 160 012 3 45 6 v op (v) i op ( u a) re s et pull-up re s i s tor current v s . re s et pin voltage v cc = 1. 8 v 8 5 ?c 25 ?c -40 ?c 0 5 10 15 20 25 3 0 3 5 40 0 0.2 0.4 0.6 0. 8 1 1.2 1.4 1.6 1. 8 2 v re s et (v) i re s et ( u a)
195 8006k?avr?10/10 attiny24/44/84 figure 21-18. reset pull-up resistor curr ent vs. reset pin voltage (v cc = 2.7v) figure 21-19. reset pull-up resistor curr ent vs. reset pin voltage (v cc = 5v) re s et pull-up re s i s tor current v s . re s et pin voltage v cc = 2.7v 8 5 ?c 25 ?c -40 ?c 0 10 20 3 0 40 50 60 0 0.5 1 1.5 2 2.5 3 v re s et (v) i re s et ( u a) re s et pull-up re s i s tor current v s . re s et pin voltage v cc = 5v 8 5 ?c 25 ?c -40 ?c 0 20 40 60 8 0 100 120 012 3 456 v re s et (v) i re s et ( u a)
196 8006k?avr?10/10 attiny24/44/84 21.7 pin driver strength figure 21-20. i/o pin output voltage vs. sink current (v cc = 3v) figure 21-21. i/o pin output voltage vs. sink current (v cc = 5v) i/o pin output voltage v s . s ink current v cc = 3 v 8 5 ?c 25 ?c -40 ?c 0 0.1 0.2 0. 3 0.4 0.5 0.6 0.7 0. 8 0.9 1 0 5 10 15 20 25 i ol (ma) v ol (v) i/o pin output voltage v s . s ink current v cc = 5v 8 5 ?c 25 ?c -40 ?c 0 0.1 0.2 0. 3 0.4 0.5 0.6 0.7 0 5 10 15 20 25 i ol (ma) v ol (v)
197 8006k?avr?10/10 attiny24/44/84 figure 21-22. i/o pin output voltage vs. source current (v cc = 3v) figure 21-23. i/o pin output voltage vs. source current (v cc = 5v) i/o pin output voltage v s . s ource current v cc = 3 v 8 5 ?c 25 ?c -40 ?c 0 0.5 1 1.5 2 2.5 3 3 .5 0 5 10 15 20 25 i oh (ma) v oh (v) i/o pin output voltage v s . s ource current v cc = 5v 8 5 ?c 25 ?c -40 ?c 4. 3 4.4 4.5 4.6 4.7 4. 8 4.9 5 5.1 0 5 10 15 20 25 i oh (ma) v oh (v)
198 8006k?avr?10/10 attiny24/44/84 figure 21-24. reset pin output voltage vs. sink current (v cc = 3v) figure 21-25. reset pin output voltage vs. sink current (v cc = 5v) re s et a s i/o pin output voltage v s . s ink current v cc = 3 v -45 c 0 c 8 5 c 0 0.5 1 1.5 00.511.522.5 3 i ol (ma) v ol (v) re s et a s i/o pin output voltage v s . s ink current v cc = 5v -45 c 0 c 8 5 c 0 0.2 0.4 0.6 0. 8 1 0 0.5 1 1.5 2 2.5 3 i ol (ma) v ol (v)
199 8006k?avr?10/10 attiny24/44/84 figure 21-26. reset pin output voltage vs. source current (v cc = 3v) figure 21-27. reset pin output voltage vs. source current (v cc = 5v) re s et a s i/o pin output voltage v s . s ource current v cc = 3 v -45 c 25 c 8 5 c 0 0.5 1 1.5 2 2.5 3 3 .5 0 0.5 1 1.5 2 i oh (ma) v oh (v) re s et a s i/o pin output voltage v s . s ource current v cc = 5v -45 c 25 c 8 5 c 2.5 3 3 .5 4 4.5 5 0 0.5 1 1.5 2 i oh (ma) v oh (v)
200 8006k?avr?10/10 attiny24/44/84 21.8 pin threshold and hysteresis figure 21-28. i/o pin input threshold voltage vs. v cc (v ih , io pin read as ?1?) figure 21-29. i/o pin input threshold voltage vs. v cc (v il , io pin read as ?0?) i/o pin input thre s hold voltage v s . v cc vih, io pin read a s '1' 8 5 ?c 25 ?c -40 ?c 0 0.5 1 1.5 2 2.5 3 3 .5 1.5 2 2.5 33 .5 4 4.5 5 5.5 v cc (v) thre s hold (v) i/o pin input thre s hold voltage v s . v cc vil, io pin read a s '0' 8 5 ?c 25 ?c -40 ?c 0 0.5 1 1.5 2 2.5 1.5 2 2.5 33 .5 4 4.5 5 5.5 v cc (v) thre s hold (v)
201 8006k?avr?10/10 attiny24/44/84 figure 21-30. i/o pin input hysteresis vs. v cc figure 21-31. reset input threshold voltage vs. v cc (v ih , i/o pin threshold as ?1?) i/o pin input hy s tere s i s v s . v cc 8 5 c 25 c -40 c 0 0.1 0.2 0. 3 0.4 0.5 0.6 1.5 2 2.5 33 .5 4 4.5 5 5.5 v cc (v) inp u t hy s tere s i s (v) re s et input thre s hold voltage v s . v cc vih, io pin read a s '1' 8 5 ?c 25 ?c -40 ?c 0 0.5 1 1.5 2 2.5 1.5 2 2.5 33 .5 4 4.5 5 5.5 v cc (v) thre s hold (v)
202 8006k?avr?10/10 attiny24/44/84 figure 21-32. reset input threshold voltage vs. v cc (v il , i/o pin read as ?0?) figure 21-33. reset pin input hysteresis vs. v cc re s et input thre s hold voltage v s . v cc vil, io pin read a s '0' 8 5 ?c 25 ?c -40 ?c 0 0.5 1 1.5 2 2.5 1.5 2 2.5 33 .5 4 4.5 5 5.5 v cc (v) thre s hold (v) reset pin input hysteresis vs. v cc v cc (v) input hysteresis (v) 85 c 25 c -40 c 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 1.5 2 2.5 3 3.5 4 4.5 5 5.5
203 8006k?avr?10/10 attiny24/44/84 figure 21-34. reset pin input hysteresis vs. v cc (reset pin used as i/o) 21.9 bod threshold and analog comparator offset figure 21-35. bod threshold vs. temperature (bodlevel is 4.3v) reset pin as i/o, input hysteresis vs. vcc v il , i/o pin read as "0" 85 c 25 c -40 c 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 v cc (v) input hysteresis (v) bod thre s hold s v s . temperature bodlevel i s 4. 3 v ri s ing v cc f a lling v cc 4.14 4.16 4.1 8 4.2 4.22 4.24 4.26 4.2 8 4. 3 4. 3 2 4. 3 4 -60 -40 -20 0 20 40 60 8 0 100 temper a t u re (c) thre s hold (v)
204 8006k?avr?10/10 attiny24/44/84 figure 21-36. bod threshold vs. temperature (bodlevel is 2.7v) figure 21-37. bod threshold vs. temperature (bodlevel is 1.8v) bod thre s hold s v s . temperature bodlevel i s 2.7v ri s ing v cc f a lling v cc 2.64 2.65 2.66 2.67 2.6 8 2.69 2.7 2.71 2.72 2.7 3 2.74 2.75 -60 -40 -20 0 20 40 60 8 0 100 temper a t u re (c) thre s hold (v) bod thre s hold s v s . temperature bodlevel i s 1. 8 v ri s ing v cc f a lling v cc 1.77 1.775 1.7 8 1.7 8 5 1.79 1.795 1. 8 1. 8 05 1. 8 1 1. 8 15 1. 8 2 -60 -40 -20 0 20 40 60 8 0 100 temper a t u re (c) thre s hold (v)
205 8006k?avr?10/10 attiny24/44/84 21.10 internal oscillator speed figure 21-38. watchdog oscillato r frequency vs. v cc figure 21-39. watchdog oscillator freq uency vs. temperature watchdog oscillator frequency vs. operating voltage 85 c 25 c -40 c 99 100 101 102 103 104 105 106 107 108 109 110 1.5 2 2.5 3 3.5 4 4.5 5 5.5 v cc (v) fre q uency (khz) watchdog oscillator frequency vs. temperature 5.5 v 4.0 v 3.3 v 2.7 v 1.8 v 100 101 102 103 104 105 106 107 108 109 110 -60 -40 -20 0 20 40 60 80 100 temperature fre q uency (khz)
206 8006k?avr?10/10 attiny24/44/84 figure 21-40. calibrated 8 mhz rc osc illator frequency vs. v cc figure 21-41. calibrated 8 mhz rc oscillato r frequency vs. temperature calibrated 8.0mhz rc oscillator frequency vs. operating voltage 85 c 25 c -40 c 1 2 3 4 5 6 7 8 9 1.5 2 2.5 3 3.5 4 4.5 5 5.5 v cc (v) fre q uency (mhz) calibrated 8.0mhz rc oscillator frequency vs. temperature 5.0 v 3.0 v 7.6 7.7 7.8 7.9 8 8.1 8.2 8.3 -60 -40 -20 0 20 40 60 80 100 temperature fre q uency (mhz)
207 8006k?avr?10/10 attiny24/44/84 figure 21-42. calibrated 8 mhz rc oscillator frequency vs. osccal value 21.11 current consumption of peripheral units figure 21-43. adc current vs. v cc calibrated 8 mhz rc o s cillator frequency v s . o s ccal value 8 5 ?c 25 ?c -40 ?c 0 2 4 6 8 10 12 14 16 016 3 24 8 64 8 0 96 112 12 8 144 160 176 192 20 8 224 240 o s ccal (x1) f rc (mhz) adc current vs. v cc 4.0 mhz frequency 0 100 200 300 400 500 600 700 1.5 2 2.5 3 3.5 4 4.5 5 5.5 v cc (v) i cc (ua)
208 8006k?avr?10/10 attiny24/44/84 figure 21-44. aref external reference current vs. v cc figure 21-45. analog comparator current vs. v cc aref external reference current v s . v cc 25 ?c 0 3 0 60 90 120 150 1 8 0 1,5 2 2,5 33 ,5 4 4,5 5 5,5 v cc (v) i cc ( u a) analog comparator current v s . v cc 0 20 40 60 8 0 100 120 140 1,5 2 2,5 33 ,5 4 4,5 5 5,5 v cc (v) i cc ( u a) 25 ?c
209 8006k?avr?10/10 attiny24/44/84 figure 21-46. programming current vs. v cc (attiny24) figure 21-47. programming current vs. v cc (attiny44) programming current vs. v cc attiny24 25 c 0 1000 2000 3000 4000 5000 6000 7000 8000 1.5 2.5 3.5 4.5 5.5 v cc (v) i cc (ua) programming current vs. v cc attiny44 25 c 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 1.5 2.5 3.5 4.5 5.5 v cc (v) i cc (ua)
210 8006k?avr?10/10 attiny24/44/84 figure 21-48. programming current vs. v cc (attiny84) figure 21-49. brownout detector current vs. v cc 25 c programming current vs. v cc attiny84 0 2000 4000 6000 8000 10000 12000 14000 16000 1.5 2 2.5 3 3.5 4 4.5 5 5.5 v cc (v) i cc (ua) brownout detector current v s . v cc 8 5 ?c 25 ?c -40 ?c 0 5 10 15 20 25 3 0 3 5 40 45 1.5 2 2.5 33 .5 4 4.5 5 5.5 v cc (v) i cc ( u a)
211 8006k?avr?10/10 attiny24/44/84 figure 21-50. watchdog timer current vs. v cc 21.12 current consumption in reset and reset pulsewidth figure 21-51. reset supply current vs. v cc (0.1 - 1.0 mhz, excluding current through the reset pull-up) watchdog timer current v s . v cc 8 5 ?c 25 ?c -40 ?c 0 1 2 3 4 5 6 7 8 9 10 1,5 2 2,5 33 ,5 4 4,5 5 5,5 v cc (v) i cc ( u a) re s et s upply current v s . v cc 0.1 - 1.0 mhz,excluding current through the re s et pullup 5.5 v 5.0 v 4.5 v 4.0 v 3 . 3 v 2.7 v 1. 8 v 0 0.02 0.04 0.06 0.0 8 0.1 0.12 0.14 0 0.1 0.2 0. 3 0.4 0.5 0.6 0.7 0. 8 0.9 1 freq u ency (mhz) i cc (ma)
212 8006k?avr?10/10 attiny24/44/84 figure 21-52. reset supply current vs. v cc (1 - 20 mhz, excluding current through the reset pull-up) figure 21-53. minimum reset pulse width vs. v cc re s et s upply current v s . v cc 1 - 20 mhz, excluding current through the re s et pullup 5.5 v 5.0 v 4.5 v 0 0.5 1 1.5 2 2.5 3 0246 8 10 12 14 16 1 8 20 freq u ency (mhz) i cc (ma) 4.0v 3 . 3 v 2.7v 1. 8 v minimum re s et pul s e width v s . v cc 8 5 ?c 25 ?c -40 ?c 0 500 1000 1500 2000 2500 1.5 2 2.5 33 .5 4 4.5 5 5.5 6 v cc (v) p u l s ewidth (n s )
213 8006k?avr?10/10 attiny24/44/84 22. register summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page 0x3f (0x5f) sreg i t h s v n z c page 8 0x3e (0x5e) sph ? ? ? ? ? ? sp9 sp8 page 11 0x3d (0x5d) spl sp7 sp6 sp5 sp4 sp3 sp2 sp1 sp0 page 11 0x3c (0x5c) ocr0b timer/counter0 ? output compare register b page 85 0x3b (0x5b) gimsk ? int0 pcie1 pcie0 ? ? ? ? page 51 0x3a (0x5a gifr ? intf0 pcif1 pcif0 ? ? ? ? page 52 0x39 (0x59) timsk0 ? ? ? ? ? ocie0b ocie0a toie0 page 85 0x38 (0x58) tifr0 ? ? ? ? ocf0b ocf0a tov0 page 85 0x37 (0x57) spmcsr ? ? rsig ctpb rflb pgwrt pgers spmen page 157 0x36 (0x56) ocr0a timer/counter0 ? output compare register a page 84 0x35 (0x55) mcucr bods pud se sm1 sm0 bodse isc01 isc00 pages 36 , 51 , and 67 0x34 (0x54) mcusr ? ? ? ? wdrf borf extrf porf page 45 0x33 (0x53) tccr0b foc0a foc0b ? ? wgm02 cs02 cs01 cs00 page 83 0x32 (0x52) tcnt0 timer/counter0 page 84 0x31 (0x51) osccalcal7cal6cal5cal4cal3cal2cal1cal0 page 30 0x30 (0x50) tccr0a com0a1 com0a0 com0b1 com0b0 ? wgm01 wgm00 page 80 0x2f (0x4f) tccr1a com1a1 com1a0 com1b1 com1b0 ? wgm11 wgm10 page 108 0x2e (0x4e) tccr1b icnc1 ices1 ? wgm13 wgm12 cs12 cs11 cs10 page 110 0x2d (0x4d) tcnt1h timer/counter1 ? counter register high byte page 112 0x2c (0x4c) tcnt1l timer/counter1 ? counter register low byte page 112 0x2b (0x4b) ocr1ah timer/counter1 ? compare register a high byte page 112 0x2a (0x4a) ocr1al timer/counter1 ? compare register a low byte page 112 0x29 (0x49) ocr1bh timer/counter1 ? compare register b high byte page 112 0x28 (0x48) ocr1bl timer/counter1 ? compare register b low byte page 112 0x27 (0x47) dwdr dwdr[7:0] page 152 0x26 (0x46) clkpr clkpce ? ? ? clkps3 clkps2 clkps1 clkps0 page 31 0x25 (0x45) icr1h timer/counter1 - input capture register high byte page 113 0x24 (0x44) icr1l timer/counter1 - input capture register low byte page 113 0x23 (0x43) gtccr tsm ? ? ? ? ? ? psr10 page 116 0x22 (0x42) tccr1c foc1a foc1b ? ? ? ? ? ? page 111 0x21 (0x41) wdtcsr wdif wdie wdp3 wdce wde wdp2 wdp1 wdp0 page 45 0x20 (0x40) pcmsk1 ? ? ? ? pcint11 pcint10 pcint9 pcint8 page 52 0x1f (0x3f) eearh ? ? ? ? ? ? ? eear8 page 20 0x1e (0x3e) eearl eear7 eear6 eear5 eear4 eear3 eear2 eear1 eear0 page 21 0x1d (0x3d) eedr eeprom data register page 21 0x1c (0x3c) eecr ? ? eepm1 eepm0 eerie eempe eepe eere page 21 0x1b (0x3b) porta porta7 porta6 porta5 p orta4 porta3 porta2 porta1 porta0 page 67 0x1a (0x3a) ddra dda7 dda6 dda5 dda4 dda3 dda2 dda1 dda0 page 67 0x19 (0x39) pina pina7 pina6 pina5 pina4 pina3 pina2 pina1 pina0 page 68 0x18 (0x38) portb ? ? ? ? portb3 portb2 portb1 portb0 page 68 0x17 (0x37) ddrb ? ? ? ? ddb3 ddb2 ddb1 ddb0 page 68 0x16 (0x36) pinb ? ? ? ? pinb3 pinb2 pinb1 pinb0 page 68 0x15 (0x35) gpior2 general purpose i/o register 2 page 23 0x14 (0x34) gpior1 general purpose i/o register 1 page 23 0x13 (0x33) gpior0 general purpose i/o register 0 page 23 0x12 (0x32) pcmsk0 pcint7 pcint6 pcint5 pcint4 pcint3 pcint2 pcint1 pcint0 page 53 0x11 (0x31)) reserved ? 0x10 (0x30) usibr usi buffer register page 125 0x0f (0x2f) usidr usi data register page 124 0x0e (0x2e) usisr usisif usioif usipf usidc usicnt3 usicnt2 usi cnt1 usicnt0 page 125 0x0d (0x2d) usicr usisie usioie usiwm1 usiwm0 usics1 usics0 usiclk usitc page 126 0x0c (0x2c) timsk1 ? ?icie1 ? ? ocie1b ocie1a toie1 page 113 0x0b (0x2b) tifr1 ? ?icf1 ? ? ocf1b ocf1a tov1 page 114 0x0a (0x2a) reserved ? 0x09 (0x29) reserved ? 0x08 (0x28) acsr acd acbg aco aci acie acic acis1 acis0 page 130 0x07 (0x27) admux refs1 refs0 mux5 mux4 mux3 mux2 mux1 mux0 page 145 0x06 (0x26) adcsra aden adsc adate adif adie adps2 adps1 adps0 page 147 0x05 (0x25) adch adc data register high byte page 149 0x04 (0x24) adcl adc data register low byte page 149 0x03 (0x23) adcsrb bin acme ?adlar ? adts2 adts1 adts0 page 131, page 149 0x02 (0x22) reserved ? 0x01 (0x21) didr0 adc7d adc6d adc5d adc4d adc3d adc2d adc1d adc0d page 131, page 150 0x00 (0x20) prr ? ? ? ? prtim1 prtim0 prusi pradc page 37
214 8006k?avr?10/10 attiny24/44/84 note: 1. for compatibility with future devices, reserved bits s hould be written to zero if accessed. reserved i/o memory addresse s should never be written. 2. i/o registers within the address range 0x00 - 0x1f are directly bit-accessible using the sbi and cbi instructions. in these registers, the value of single bits can be ch ecked by using the sbis and sbic instructions. 3. some of the status flags are cleared by writing a logical o ne to them. note that, unlike most other avrs, the cbi and sbi instructions will only operation the specified bit, and can theref ore be used on registers contai ning such status flags. the cbi and sbi instructions work wit h registers 0x00 to 0x1f only.
215 8006k?avr?10/10 attiny24/44/84 23. instruction set summary mnemonics operands description operation flags #clocks arithmetic and logic instructions add rd, rr add two registers rd rd + rr z,c,n,v,h 1 adc rd, rr add with carry two registers rd rd + rr + c z,c,n,v,h 1 adiw rdl,k add immediate to word rdh:rdl rdh:rdl + k z,c,n,v,s 2 sub rd, rr subtract two registers rd rd - rr z,c,n,v,h 1 subi rd, k subtract constant from register rd rd - k z,c,n,v,h 1 sbc rd, rr subtract with carry two registers rd rd - rr - c z,c,n,v,h 1 sbci rd, k subtract with carry constant from reg. rd rd - k - c z,c,n,v,h 1 sbiw rdl,k subtract immediate from word rdh:rdl rdh:rdl - k z,c,n,v,s 2 and rd, rr logical and registers rd rd ? rr z,n,v 1 andi rd, k logical and register and constant rd rd ? k z,n,v 1 or rd, rr logical or registers rd rd v rr z,n,v 1 ori rd, k logical or register and constant rd rd v k z,n,v 1 eor rd, rr exclusive or registers rd rd rr z,n,v 1 com rd one?s complement rd 0xff ? rd z,c,n,v 1 neg rd two?s complement rd 0x00 ? rd z,c,n,v,h 1 sbr rd,k set bit(s) in register rd rd v k z,n,v 1 cbr rd,k clear bit(s) in register rd rd ? (0xff - k) z,n,v 1 inc rd increment rd rd + 1 z,n,v 1 dec rd decrement rd rd ? 1 z,n,v 1 tst rd test for zero or minus rd rd ? rd z,n,v 1 clr rd clear register rd rd rd z,n,v 1 ser rd set register rd 0xff none 1 branch instructions rjmp k relative jump pc pc + k + 1 none 2 ijmp indirect jump to (z) pc z none 2 rcall k relative subroutine call pc pc + k + 1 none 3 icall indirect call to (z) pc znone3 ret subroutine return pc stack none 4 reti interrupt return pc stack i 4 cpse rd,rr compare, skip if equal if (rd = rr) pc pc + 2 or 3 none 1/2/3 cp rd,rr compare rd ? rr z, n,v,c,h 1 cpc rd,rr compare with carry rd ? rr ? c z, n,v,c,h 1 cpi rd,k compare register with immediate rd ? k z, n,v,c,h 1 sbrc rr, b skip if bit in register cleared if (rr(b)=0) pc pc + 2 or 3 none 1/2/3 sbrs rr, b skip if bit in register is set if (rr(b)=1) pc pc + 2 or 3 none 1/2/3 sbic p, b skip if bit in i/o register cleared if (p(b)=0) pc pc + 2 or 3 none 1/2/3 sbis p, b skip if bit in i/o register is set if (p(b)=1) pc pc + 2 or 3 none 1/2/3 brbs s, k branch if status flag set if (sreg(s) = 1) then pc pc+k + 1 none 1/2 brbc s, k branch if status flag cleared if (sreg(s) = 0) then pc pc+k + 1 none 1/2 breq k branch if equal if (z = 1) then pc pc + k + 1 none 1/2 brne k branch if not equal if (z = 0) then pc pc + k + 1 none 1/2 brcs k branch if carry set if (c = 1) then pc pc + k + 1 none 1/2 brcc k branch if carry cleared if (c = 0) then pc pc + k + 1 none 1/2 brsh k branch if same or higher if (c = 0) then pc pc + k + 1 none 1/2 brlo k branch if lower if (c = 1) then pc pc + k + 1 none 1/2 brmi k branch if minus if (n = 1) then pc pc + k + 1 none 1/2 brpl k branch if plus if (n = 0) then pc pc + k + 1 none 1/2 brge k branch if greater or equal, signed if (n v= 0) then pc pc + k + 1 none 1/2 brlt k branch if less than zero, signed if (n v= 1) then pc pc + k + 1 none 1/2 brhs k branch if half carry flag set if (h = 1) then pc pc + k + 1 none 1/2 brhc k branch if half carry flag cleared if (h = 0) then pc pc + k + 1 none 1/2 brts k branch if t flag set if (t = 1) then pc pc + k + 1 none 1/2 brtc k branch if t flag cleared if (t = 0) then pc pc + k + 1 none 1/2 brvs k branch if overflow flag is set if (v = 1) then pc pc + k + 1 none 1/2 brvc k branch if overflow flag is cleared if (v = 0) then pc pc + k + 1 none 1/2 brie k branch if interrupt enabled if ( i = 1) then pc pc + k + 1 none 1/2 brid k branch if interrupt disabled if ( i = 0) then pc pc + k + 1 none 1/2 bit and bit-test instructions sbi p,b set bit in i/o register i/o(p,b) 1none2 cbi p,b clear bit in i/o register i/o(p,b) 0none2 lsl rd logical shift left rd(n+1) rd(n), rd(0) 0 z,c,n,v 1 lsr rd logical shift right rd(n) rd(n+1), rd(7) 0 z,c,n,v 1 rol rd rotate left through carry rd(0) c,rd(n+1) rd(n),c rd(7) z,c,n,v 1
216 8006k?avr?10/10 attiny24/44/84 ror rd rotate right through carry rd(7) c,rd(n) rd(n+1),c rd(0) z,c,n,v 1 asr rd arithmetic shift right rd(n) rd(n+1), n=0..6 z,c,n,v 1 swap rd swap nibbles rd(3..0) rd(7..4),rd(7..4) rd(3..0) none 1 bset s flag set sreg(s) 1 sreg(s) 1 bclr s flag clear sreg(s) 0 sreg(s) 1 bst rr, b bit store from register to t t rr(b) t 1 bld rd, b bit load from t to register rd(b) tnone1 sec set carry c 1c1 clc clear carry c 0 c 1 sen set negative flag n 1n1 cln clear negative flag n 0 n 1 sez set zero flag z 1z1 clz clear ze ro flag z 0 z 1 sei global interrupt enable i 1i1 cli global interrupt disable i 0 i 1 ses set signed test flag s 1s1 cls clear signed test flag s 0 s 1 sev set twos complement overflow. v 1v1 clv clear twos complement overflow v 0 v 1 set set t in sreg t 1t1 clt clear t in sreg t 0 t 1 seh set half carry flag in sreg h 1h1 clh clear half carry flag in sreg h 0 h 1 data transfer instructions mov rd, rr move between registers rd rr none 1 movw rd, rr copy register word rd+1:rd rr+1:rr none 1 ldi rd, k load immediate rd knone1 ld rd, x load indirect rd (x) none 2 ld rd, x+ load indirect and post-inc. rd (x), x x + 1 none 2 ld rd, - x load indirect and pre-dec. x x - 1, rd (x) none 2 ld rd, y load indirect rd (y) none 2 ld rd, y+ load indirect and post-inc. rd (y), y y + 1 none 2 ld rd, - y load indirect and pre-dec. y y - 1, rd (y) none 2 ldd rd,y+q load indirect with displacement rd (y + q) none 2 ld rd, z load indirect rd (z) none 2 ld rd, z+ load indirect and post-inc. rd (z), z z+1 none 2 ld rd, -z load indirect and pre-dec. z z - 1, rd (z) none 2 ldd rd, z+q load indirect with displacement rd (z + q) none 2 lds rd, k load direct from sram rd (k) none 2 st x, rr store indirect (x) rr none 2 st x+, rr store indirect and post-inc. (x) rr, x x + 1 none 2 st - x, rr store indirect and pre-dec. x x - 1, (x) rr none 2 st y, rr store indirect (y) rr none 2 st y+, rr store indirect and post-inc. (y) rr, y y + 1 none 2 st - y, rr store indirect and pre-dec. y y - 1, (y) rr none 2 std y+q,rr store indirect with displacement (y + q) rr none 2 st z, rr store indirect (z) rr none 2 st z+, rr store indirect and post-inc. (z) rr, z z + 1 none 2 st -z, rr store indirect and pre-dec. z z - 1, (z) rr none 2 std z+q,rr store indirect with displacement (z + q) rr none 2 sts k, rr store direct to sram (k) rr none 2 lpm load program memory r0 (z) none 3 lpm rd, z load program memory rd (z) none 3 lpm rd, z+ load program memory and post-inc rd (z), z z+1 none 3 spm store program memory (z) r1:r0 none in rd, p in port rd pnone1 out p, rr out port p rr none 1 push rr push register on stack stack rr none 2 pop rd pop register from stack rd stack none 2 mcu control instructions nop no operation none 1 sleep sleep (see specific descr. for sleep function) none 1 wdr watchdog reset (see specific descr. for wdr/timer) none 1 break break for on-chip debug only none n/a mnemonics operands description operation flags #clocks
217 8006k?avr?10/10 attiny24/44/84 24. ordering information notes: 1. code indicators: ? u: matte tin ? r: tape & reel 2. all packages are pb-free, halide-free and fully green and they comply with the european directive for restriction of hazard- ous substances (rohs). 3. these devices can also be supplied in wafer form. please contact your local atmel sales office for detailed ordering informa- tion and minimum quantities. 24.1 attiny24 speed (mhz) power supply ordering code (1) package (2) operational range 10 1.8 - 5.5v attiny24v-10ssu attiny24v-10ssur attiny24v-10pu attiny24v-10mu ATTINY24V-10MUR 14s1 14s1 14p3 20m1 20m1 industrial (-40 c to +85 c) (3) 20 2.7 - 5.5v attiny24-20ssu attiny24-20ssur attiny24-20pu attiny24-20mu attiny24-20mur 14s1 14s1 14p3 20m1 20m1 industrial (-40 c to +85 c) (3) package type 14s1 14-lead, 0.150" wide body, plastic gull wing small outline package (soic) 14p3 14-lead, 0.300" wide, plastic dual inline package (pdip) 20m1 20-pad, 4 x 4 x 0.8 mm body, quad flat no -lead/micro lead frame package (qfn/mlf)
218 8006k?avr?10/10 attiny24/44/84 notes: 1. code indicators: ? u: matte tin ? r: tape & reel 2. all packages are pb-free, halide-free and fully green and they comply with the european directive for restriction of hazard- ous substances (rohs). 3. these devices can also be supplied in wafer form. please contact your local atmel sales office for detailed ordering informa- tion and minimum quantities. 24.2 attiny44 speed (mhz) power supply ordering code (1) package (2) operational range 10 1.8 - 5.5v attiny44v-10ssu attiny44v-10ssur attiny44v-10pu attiny44v-10mu attiny44v-10mur 14s1 14s1 14p3 20m1 20m1 industrial (-40 c to +85 c) (3) 20 2.7 - 5.5v attiny44-20ssu attiny44-20ssur attiny44-20pu attiny44-20mu attiny44-20mur 14s1 14s1 14p3 20m1 20m1 industrial (-40 c to +85 c) (3) package type 14s1 14-lead, 0.150" wide body, plastic gull wing small outline package (soic) 14p3 14-lead, 0.300" wide, plastic dual inline package (pdip) 20m1 20-pad, 4 x 4 x 0.8 mm body, quad flat no -lead/micro lead frame package (qfn/mlf)
219 8006k?avr?10/10 attiny24/44/84 notes: 1. code indicators: ? u: matte tin ? r: tape & reel 2. all packages are pb-free, halide-free and fully green and they comply with the european directive for restriction of hazard- ous substances (rohs). 3. these devices can also be supplied in wafer form. please contact your local atmel sales office for detailed ordering informa- tion and minimum quantities. 24.3 attiny84 speed (mhz) power supply ordering code (1) package (2) operational range 10 1.8 - 5.5v attiny84v-10ssu attiny84v-10ssur attiny84v-10pu attiny84v-10mu attiny84v-10mur 14s1 14s1 14p3 20m1 20m1 industrial (-40 c to +85 c) (3) 20 2.7 - 5.5v attiny84-20ssu attiny84-20ssur attiny84-20pu attiny84-20mu attiny84-20mur 14s1 14s1 14p3 20m1 20m1 industrial (-40 c to +85 c) (3) package type 14s1 14-lead, 0.150" wide body, plastic gull wing small outline package (soic) 14p3 14-lead, 0.300" wide, plastic dual inline package (pdip) 20m1 20-pad, 4 x 4 x 0.8 mm body, quad flat no -lead/micro lead frame package (qfn/mlf)
220 8006k?avr?10/10 attiny24/44/84 25. packaging information 25.1 20m1 2325 orchard parkway san jose, ca 95131 title drawing no. r rev. 20m1 , 20-pad, 4 x 4 x 0.8 mm body, lead pitch 0.50 mm, a 20m1 10/27/04 2.6 mm exposed pad, micro lead frame package (mlf) a 0.70 0.75 0.80 a1 ? 0.01 0.05 a2 0.20 ref b 0.18 0.23 0.30 d 4.00 bsc d2 2.45 2.60 2.75 e 4.00 bsc e2 2.45 2.60 2.75 e 0.50 bsc l 0.35 0.40 0.55 side view pin 1 id pin #1 notch (0.20 r) bottom view top view note: reference jedec standard mo-220, fig . 1 (saw singulation) wggd-5. common dimensions (unit of measure = mm) symbol min nom max note d e e a2 a1 a d2 e2 0.08 c l 1 2 3 b 1 2 3
221 8006k?avr?10/10 attiny24/44/84 25.2 14p3 2325 orchard parkway san jose, ca 95131 title drawing no. r rev. 14p 3 , 14-lead (0.300"/7.62 mm wide) plastic dual inline package (pdip) a 14p3 11/02/05 pin 1 e1 a1 b e b1 c l seating plane a d e eb ec common dimen s ion s (unit of measure = mm) s ymbol min nom max note a ? ? 5.334 a1 0.381 ? ? d 18.669 ? 19.685 note 2 e 7.620 ? 8.255 e1 6.096 ? 7.112 note 2 b 0.356 ? 0.559 b1 1.143 ? 1.778 l 2.921 ? 3.810 c 0.203 ? 0.356 eb ? ? 10.922 ec 0.000 ? 1.524 e 2.540 typ notes: 1. this package conforms to jedec reference ms-001, variation aa. 2. dimensions d and e1 do not include mold flash or protrusion. mold flash or protrusion shall not exceed 0.25 mm (0.010").
222 8006k?avr?10/10 attiny24/44/84 25.3 14s1 2325 orchard parkway san jose, ca 95131 title drawing no. r rev. 14s1 , 14-lead, 0.150" wide body, plastic gull wing small outline package (soic) 2/5/02 14s1 a a1 e l side view top view end view h e b n 1 e a d common dimensions (unit of measure = mm/inches) symbol min nom max note notes: 1. this drawing is for general information only; refer to jedec drawing ms-012, variation ab for additional information. 2. dimension d does not include mold flash, protrusions or gate burrs. mold flash, protrusion and gate burrs shall not exceed 0.15 mm (0.006") per side. 3. dimension e does not include inter-lead flash or protrusion. inter-lead flash and protrusions shall not exceed 0.25 mm (0.010") per side. 4. l is the length of the terminal for soldering to a substrate. 5. the lead width b, as measured 0.36 mm (0.014") or greater above the seating plane, shall not exceed a maximum value of 0.61 mm (0.024") per side. a 1.35/0.0532 ? 1.75/0.0688 a1 0.1/.0040 ? 0.25/0.0098 b 0.33/0.0130 ? 0.5/0.0200 5 d 8.55/0.3367 ? 8.74/0.3444 2 e 3.8/0.1497 ? 3.99/0.1574 3 h 5.8/0.2284 ? 6.19/0.2440 l 0.41/0.0160 ? 1.27/0.0500 4 e 1.27/0.050 bsc
223 8006k?avr?10/10 attiny24/44/84 26. errata the revision letters in this section refer to the revision of the corresponding attiny24/44/84 device. 26.1 attiny24 26.1.1 rev. d ? e no known errata. 26.1.2 rev. c ? reading eeprom when system clock fr equency is below 900 khz may not work 1. reading eeprom when system clock frequency is below 900 khz may not work reading data from the eeprom at system clock frequency below 900 khz may result in wrong data read. problem fix/work around avoid using the eeprom at clock frequency below 900 khz. 26.1.3 rev. b ? eeprom read from applicat ion code does not work in lock bit mode 3 ? reading eeprom when system clock fr equency is below 900 khz may not work 1. eeprom read from applic ation code does not work in lock bit mode 3 when the memory lock bits lb2 and lb1 are programmed to mode 3, eeprom read does not work from the application code. problem fix/work around do not set lock bit protection mode 3 when the application code needs to read from eeprom. 2. reading eeprom when system clock frequency is below 900 khz may not work reading data from the eeprom at system clock frequency below 900 khz may result in wrong data read. problem fix/work around avoid using the eeprom at clock frequency below 900 khz. 26.1.4 rev. a not sampled.
224 8006k?avr?10/10 attiny24/44/84 26.2 attiny44 26.2.1 rev. b ? d no known errata. 26.2.2 rev. a ? reading eeprom when system clock fr equency is below 900 khz may not work 1. reading eeprom when system clock frequency is below 900 khz may not work reading data from the eeprom at system clock frequency below 900 khz may result in wrong data read. problem fix/work around avoid using the eeprom at clock frequency below 900 khz.
225 8006k?avr?10/10 attiny24/44/84 26.3 attiny84 26.3.1 rev. a ? b no known errata.
226 8006k?avr?10/10 attiny24/44/84 27. datasheet revision history 27.1 rev k. - 10/10 1. added note for internal 1.1v reference in table 16-4 on page 146 . 2. added tape & reel in section 24. ?ordering information? on page 217 . 3. updated last page. 27.2 rev j. - 08/10 1. updated section 6.4 ?clock output buffer? on page 30 , changed clko to ckout. 2. removed text "not recommended for new design" from cover page. 27.3 rev i. - 06/10 1. removed ?preliminary? from cover page. 2. updated notes in table 19-16, ?high-voltage serial programming instruction set for attiny24/44/84,? on page 171 . 3. added clarification before table 6-8, ?capacitance for the low-frequency crystal oscillator,? on page 28 . 4. updated some table notes in section 20. ?electrical characteristics? on page 174 . 27.4 rev h. 10/09 1. updated document template. re-arranged some sections. 2. updated ?low-frequency crystal oscillator? with the table 6-8 on page 28 3. updated tables: ? ?active clock domains and wake-up sources in different sleep modes? on page 33 ? ?dc characteristics? on page 174 ? ?register summary? on page 213 4. updated register description: ? ?admux ? adc multiplexer sele ction register? on page 145 5. signature imprint reading instructions updated in ?reading device signature imprint table from firmware? on page 156 . 6. updated section: ? step 1. on page 164 7. added table: ? ?analog comparator characteristics? on page 179 8. updated figure: ? ?active supply current vs. frequency (1 - 20 mhz)? on page 187 9. updated figure 21-30 on page 201 and figure 21-33 on page 202 under ?pin thresh- old and hysteresis?. 10. changed attiny24/44 device status to ?not recommended for new designs. use: attiny24a/44a?. 27.5 rev g. 01/08 1. updated sections: ? ?features? on page 1
227 8006k?avr?10/10 attiny24/44/84 ? ?reset? on page 3 ? ?overview? on page 4 ? ?about? on page 6 ? ?sph and spl ? stack pointer register? on page 11 ? ?atomic byte programming? on page 17 ? ?write? on page 17 ? ?clock sources? on page 25 ? ?default clock source? on page 30 ? ?sleep modes? on page 33 ? ?software bod disable? on page 34 ? ?external interrupts? on page 49 ? ?usibr ? usi data buffer? on page 125 ? ?usidr ? usi data register? on page 124 ? ?didr0 ? digital input disable register 0? on page 131 ? ?features? on page 132 ? ?prescaling and conversion timing? on page 135 ? ?temperature measurement? on page 144 ? ?admux ? adc multiplexer sele ction register? on page 145 ? ?limitations of debugwire? on page 152 ? ?reading lock, fuse and signature data from software? on page 155 ? ?device signature imprint table? on page 161 ? ?enter high-voltage serial programming mode? on page 168 ? ?absolute maximum ratings*? on page 174 ? ?dc characteristics? on page 174 ? ?speed? on page 175 ? ?clock characteristics? on page 176 ? ?accuracy of calibrated internal rc oscillator? on page 176 ? ?system and reset characteristics? on page 177 ? ?supply current of i/o modules? on page 185 ? ?attiny24? on page 223 ? ?attiny44? on page 224 ? ?attiny84? on page 225 2. updated bit definitions in sections: ? ?mcucr ? mcu control register? on page 36 ? ?mcucr ? mcu control register? on page 51 ? ?mcucr ? mcu control register? on page 67 ? ?pina ? port a input pins? on page 68 ? ?spmcsr ? store program memory control and status register? on page 157 ? ?register summary? on page 213 3. updated figures: ? ?reset logic? on page 39
228 8006k?avr?10/10 attiny24/44/84 ? ?watchdog reset during operation? on page 42 ? ?compare match output unit, schematic (non-pwm mode)? on page 95 ? ?analog to digital converter block schematic? on page 133 ? ?adc timing diagram, free running conversion? on page 137 ? ?analog input circuitry? on page 140 ? ?high-voltage serial programming? on page 167 ? ?serial programming timing? on page 183 ? ?high-voltage serial programming timing? on page 184 ? ?active supply current vs. low frequency (0.1 - 1.0 mhz)? on page 186 ? ?active supply current vs. frequency (1 - 20 mhz)? on page 187 ? ?active supply current vs. v cc (internal rc oscillator, 8 mhz)? on page 187 ? ?active supply current vs. v cc (internal rc oscillator, 1 mhz)? on page 188 ? ?active supply current vs. v cc (internal rc oscillator, 128 khz)? on page 188 ? ?idle supply current vs. low frequency (0.1 - 1.0 mhz)? on page 189 ? ?idle supply current vs. frequency (1 - 20 mhz)? on page 189 ? ?idle supply current vs. v cc (internal rc oscillator, 8 mhz)? on page 190 ? ?idle supply current vs. v cc (internal rc oscillator, 1 mhz)? on page 190 ? ?idle supply current vs. v cc (internal rc oscillator, 128 khz)? on page 191 ? ?power-down supply current vs. v cc (watchdog timer disabled)? on page 191 ? ?power-down supply current vs. v cc (watchdog timer enabled)? on page 192 ? ?reset pin input hysteresis vs. v cc ? on page 202 ? ?reset pin input hysteresis vs. v cc (reset pin used as i/o)? on page 203 ? ?watchdog oscillator frequency vs. v cc ? on page 205 ? ?watchdog oscillator frequency vs. temperature? on page 205 ? ?calibrated 8 mhz rc oscillator frequency vs. v cc ? on page 206 ? ?calibrated 8 mhz rc oscillator frequency vs. temperature? on page 206 ? ?adc current vs. v cc ? on page 207 ? ?programming current vs. v cc (attiny24)? on page 209 ? ?programming current vs. v cc (attiny44)? on page 209 ? ?programming current vs. v cc (attiny84)? on page 210 4. added figures: ? ?reset pin output voltage vs. sink current (v cc = 3v)? on page 198 ? ?reset pin output voltage vs. sink current (v cc = 5v)? on page 198 ? ?reset pin output voltage vs. source current (v cc = 3v)? on page 199 ? ?reset pin output voltage vs. source current (v cc = 5v)? on page 199 5. updated tables: ? ?device clocking options select? on page 25 ? ?start-up times for the crystal o scillator clock selection? on page 29 ? ?start-up times for the internal calibrat ed rc oscillator clock se lection? on page 27 ? ?start-up times for the external clock selection? on page 26 ? ?start-up times for the 128 khz internal oscillator? on page 27
229 8006k?avr?10/10 attiny24/44/84 ? ?active clock domains and wake-up sources in different sleep modes? on page 33 ? ?watchdog timer prescale select? on page 47 ? ?reset and interrupt vectors? on page 48 ? ?overriding signals for alternate functions in pa7:pa5? on page 63 ? ?overriding signals for alternate functions in pa4:pa2? on page 64 ? ?overriding signals for alternate functions in pa1:pa0? on page 64 ? ?port b pins alternate functions? on page 65 ? ?overriding signals for alternate functions in pb3:pb2? on page 66 ? ?overriding signals for alternate functions in pb1:pb0? on page 67 ? ?waveform generation modes? on page 110 ? ?adc conversion time? on page 138 ? ?temperature vs. sensor output voltage (typical case)? on page 144 ? ?dc characteristics. t a = -40c to +85c? on page 174 ? ?calibration accuracy of intern al rc oscillator? on page 176 ? ?reset, brown-out, and internal voltage characteristics? on page 177 ? ?vbot vs. bodlevel fuse coding? on page 179 ? ?adc characteristics, single ended channels. t = -40c to +85c? on page 180 ? ?adc characteristics, differentia l channels (bipolar mode), t a = -40c to +85c? on page 182 ? ?serial programming characteristics, t a = -40c to +85c, v cc = 1.8 - 5.5v (unless otherwise noted)? on page 183 ? ?high-voltage serial programming characteristics t a = 25c, v cc = 5v (unless otherwise noted)? on page 184 6. updated code examples in sections: ? ?write? on page 17 ? ?spi master operation example? on page 119 7. updated ?ordering information? in: ? ?attiny84? on page 219 27.6 rev f. 02/07 1. updated figure 1-1 on page 2 , figure 8-7 on page 43 , figure 20-6 on page 184 . 2. updated table 9-1 on page 48 , table 10-7 on page 65 , table 11-2 on page 80 , table 11-3 on page 81 , table 11-5 on page 81 , table 11-6 on page 82 , table 11-7 on page 82 , table 11-8 on page 83 , table 20-11 on page 182 , table 20-13 on page 184 . 3. updated table references in ?tccr0a ? timer/counter control register a? on page 80 . 4. updated port b, bit 0 functions in ?alternate functions of port b? on page 65 . 5. updated wdtcr bit name to wdtcsr in assembly code examples. 6. updated bit5 name in ?tifr1 ? timer/counter interrupt flag register 1? on page 114 . 7. updated bit5 in ?tifr1 ? timer/counter interrupt flag register 1? on page 114 . 8. updated ?spi master operation example? on page 119 . 9. updated step 5 in ?enter high-voltage serial programming mode? on page 168 .
230 8006k?avr?10/10 attiny24/44/84 27.7 rev e. 09/06 27.8 rev d. 08/06 27.9 rev c. 07/06 27.10 rev b. 05/06 27.11 rev a. 12/05 initial revision. 1. all characterization data moved to ?electrical characteristics? on page 174 . 2. all register descriptions gathered up in separate sections at the end of each chapter. 3. updated ?system control and reset? on page 39 . 4. updated table 11-3 on page 81 , table 11-6 on page 82 , table 11-8 on page 83 , table 12-3 on page 109 and table 12-5 on page 110 . 5. updated ?fast pwm mode? on page 97 . 6. updated figure 12-7 on page 98 and figure 16-1 on page 133 . 7. updated ?analog comparator multiplexed input? on page 129 . 8. added note in table 19-12 on page 165 . 9. updated ?electrical characteri stics? on page 174 . 10. updated ?typical characteristics? on page 185 . 1. updated ?calibrated intern al 8 mhz oscillator? on page 26 . 2. updated ?osccal ? oscillator calibration register? on page 30 . 3. added table 20-2 on page 176 . 4. updated code examples in ?spi master operation example? on page 119 . 5. updated code examples in ?spi slave operation example? on page 121 . 6. updated ?signature bytes? on page 162 . 1. updated features in ?usi ? universal serial interface? on page 117 . 2. added ?clock speed considerations? on page 123 . 3. updated bit description in ?admux ? adc multiplexer selection register? on page 145 . 4. added note to table 18-1 on page 157 . 1. updated ?default clock source? on page 30 2. updated ?power reduction register? on page 35 . 3. updated table 20-4 on page 177 , table 9-4 on page 42 , table 16-3 on page 145 , table 19-5 on page 161 , table 19-12 on page 165 , table 19-16 on page 171 , table 20- 11 on page 182 . 4. updated features in ?analog to digital converter? on page 132 . 5. updated operation in ?analog to digital converter? on page 132 . 6. updated ?temperature measurement? on page 144 . 7. updated dc characteristics in ?electrical characteristics? on page 174 . 8. updated ?typical characteristics? on page 185 . 9. updated ?errata? on page 223 .
i 8006k?avr?10/10 attiny24/44/84 table of contents features ................ ................ .............. ............... .............. .............. ............ 1 1 pin configurations ..... ................ ................. ................ ................. ............ 2 1.1 pin descriptions .................................................................................................2 2 overview ............ ................ ................ ............... .............. .............. ............ 4 3 about ............. ................ ................. ................ ................. .............. ............ 6 3.1 resources .........................................................................................................6 3.2 code examples .................................................................................................6 3.3 data retention ...................................................................................................6 3.4 disclaimer ..........................................................................................................6 4cpu core ............... .............. .............. ............... .............. .............. ............ 7 4.1 architectural overview .......................................................................................7 4.2 alu ? arithmetic logic unit ...............................................................................8 4.3 status register ..................................................................................................8 4.4 general purpose register file ........................................................................10 4.5 stack pointer ...................................................................................................11 4.6 instruction execution timing ...........................................................................12 4.7 reset and interrupt handling ...........................................................................12 5 memories ............... .............. .............. ............... .............. .............. .......... 15 5.1 in-system re-programmable flash program memory ....................................15 5.2 sram data memory ........................................................................................15 5.3 eeprom data memory . ................. ................ ............. ............ ............. ..........16 5.4 i/o memory ......................................................................................................20 5.5 register description ........................................................................................20 6 clock system ........... ................ ................ ................. ................ ............. 24 6.1 clock subsystems ...........................................................................................24 6.2 clock sources .................................................................................................25 6.3 system clock prescaler ..................................................................................30 6.4 clock output buffer .........................................................................................30 6.5 register description ........................................................................................30 7 power management and sleep mo des ............... .............. ............ ........ 33 7.1 sleep modes ....................................................................................................33 7.2 software bod disable .....................................................................................34
ii 8006k?avr?10/10 attiny24/44/84 7.3 power reduction register ...............................................................................35 7.4 minimizing power consumption ......................................................................35 7.5 register description ........................................................................................36 8 system control and reset ...... ................ ................. ................ ............. 39 8.1 resetting the avr ...........................................................................................39 8.2 reset sources .................................................................................................40 8.3 internal voltage reference ..............................................................................42 8.4 watchdog timer ..............................................................................................42 8.5 register description ........................................................................................45 9 interrupts ........ ................. ................ ................. .............. .............. .......... 48 9.1 interrupt vectors ..............................................................................................48 9.2 external interrupts ...........................................................................................49 9.3 register description ........................................................................................51 10 i/o ports ............... ................ .............. ............... .............. .............. .......... 54 10.1 ports as general digital i/o .............................................................................55 10.2 alternate port functions ..................................................................................58 10.3 register description ........................................................................................67 11 8-bit timer/counter0 with pw m .............. ................. ................ ............. 69 11.1 features ..........................................................................................................69 11.2 overview ..........................................................................................................69 11.3 clock sources .................................................................................................70 11.4 counter unit ....................................................................................................70 11.5 output compare unit .......................................................................................71 11.6 compare match output unit ............................................................................73 11.7 modes of operation .........................................................................................74 11.8 timer/counter timing diagrams .....................................................................78 11.9 register description ........................................................................................80 12 16-bit timer/counter1 ......... .............. ............... .............. .............. .......... 87 12.1 features ..........................................................................................................87 12.2 overview ..........................................................................................................87 12.3 timer/counter clock sources .........................................................................89 12.4 counter unit ....................................................................................................89 12.5 input capture unit ...........................................................................................90 12.6 output compare units .....................................................................................92
iii 8006k?avr?10/10 attiny24/44/84 12.7 compare match output unit ............................................................................94 12.8 modes of operation .........................................................................................96 12.9 timer/counter timing diagrams ...................................................................103 12.10 accessing 16-bit registers ............................................................................105 12.11 register description ......................................................................................108 13 timer/counter prescaler ....... ................ ................. ................ ............. 115 13.1 prescaler reset .............................................................................................115 13.2 external clock source ...................................................................................115 13.3 register description ......................................................................................116 14 usi ? universal seri al interface ............ ................. ................ ............. 117 14.1 features ........................................................................................................117 14.2 overview ........................................................................................................117 14.3 functional descriptions .................................................................................118 14.4 alternative usi usage ...................................................................................124 14.5 register descriptions ....................................................................................124 15 analog comparator .......... .............. .............. .............. .............. ........... 129 15.1 analog comparator multiplexed input ...........................................................129 15.2 register description ......................................................................................130 16 analog to digital converter ............. ............... .............. .............. ........ 132 16.1 features ........................................................................................................132 16.2 overview ........................................................................................................132 16.3 operation .......................................................................................................133 16.4 starting a conversion ....................................................................................134 16.5 prescaling and conversion timing ................................................................135 16.6 changing channel or reference selection ...................................................138 16.7 adc noise canceler .....................................................................................139 16.8 analog input circuitry ....................................................................................139 16.9 noise canceling techniques .........................................................................140 16.10 adc accuracy definitions .............................................................................140 16.11 adc conversion result .................................................................................143 16.12 temperature measurement ...........................................................................144 16.13 register description ......................................................................................145 17 debugwire on-chip debug s ystem .............. .............. .............. ........ 151 17.1 features ........................................................................................................151
iv 8006k?avr?10/10 attiny24/44/84 17.2 overview ........................................................................................................151 17.3 physical interface ..........................................................................................151 17.4 software break points ...................................................................................152 17.5 limitations of debugwire .............................................................................152 17.6 register description ......................................................................................152 18 self-programming the flash .. ............... ................. ................ ............. 153 18.1 performing page erase by spm ....................................................................153 18.2 filling the temporary buffer (page loading) .................................................153 18.3 performing a page write ...............................................................................154 18.4 addressing the flash during self-programming ...........................................154 18.5 eeprom write prevents writing to spmcsr ............. ............ ............. ........155 18.6 reading lock, fuse and signature data from software ...............................155 18.7 preventing flash corruption ..........................................................................157 18.8 programming time for flash when using spm ............................................157 18.9 register description ......................................................................................157 19 memory programming ........ .............. ............... .............. .............. ........ 159 19.1 program and data memory lock bits ...........................................................159 19.2 fuse bytes .....................................................................................................160 19.3 device signature imprint table .....................................................................161 19.4 page size ......................................................................................................162 19.5 serial programming .......................................................................................163 19.6 high-voltage serial programming ..................................................................167 19.7 high-voltage serial programming algorithm .................................................168 20 electrical characteristics ... .............. ............... .............. .............. ........ 174 20.1 absolute maximum ratings* .........................................................................174 20.2 dc characteristics .........................................................................................174 20.3 speed ............................................................................................................175 20.4 clock characteristics .....................................................................................176 20.5 system and reset characteristics ................................................................177 20.6 analog comparator characteristics ...............................................................179 20.7 adc characteristics ......................................................................................180 20.8 serial programming characteristics ..............................................................183 20.9 high-voltage serial programming characteristics ........................................184 21 typical characteristics ....... .............. ............... .............. .............. ........ 185 21.1 supply current of i/o modules ......................................................................185
v 8006k?avr?10/10 attiny24/44/84 21.2 active supply current ....................................................................................186 21.3 idle supply current ........................................................................................189 21.4 power-down supply current ..........................................................................191 21.5 standby supply current ................................................................................192 21.6 pin pull-up .....................................................................................................193 21.7 pin driver strength ........................................................................................196 21.8 pin threshold and hysteresis ........................................................................200 21.9 bod threshold and analog comparator offset ............................................203 21.10 internal oscillator speed ...............................................................................205 21.11 current consumption of peripheral units ......................................................207 21.12 current consumption in reset and reset pulsewidth ..................................211 22 register summary ............ .............. .............. .............. .............. ........... 213 23 instruction set summary ... .............. ............... .............. .............. ........ 215 24 ordering information .......... .............. ............... .............. .............. ........ 217 24.1 attiny24 ........................................................................................................217 24.2 attiny44 ........................................................................................................218 24.3 attiny84 ........................................................................................................219 25 packaging information .......... ................ ................. ................ ............. 220 25.1 20m1 ..............................................................................................................220 25.2 14p3 ..............................................................................................................221 25.3 14s1 ..............................................................................................................222 26 errata ........... ................ ................ ................. ................ .............. ........... 223 26.1 attiny24 ........................................................................................................223 26.2 attiny44 ........................................................................................................224 26.3 attiny84 ........................................................................................................225 27 datasheet revision history .. ................ ................. ................ ............. 226 27.1 rev k. - 10/10 ................................................................................................226 27.2 rev j. - 08/10 ................................................................................................226 27.3 rev i. - 06/10 .................................................................................................226 27.4 rev h. 10/09 ..................................................................................................226 27.5 rev g. 01/08 .................................................................................................226 27.6 rev f. 02/07 ..................................................................................................229 27.7 rev e. 09/06 ..................................................................................................230 27.8 rev d. 08/06 ..................................................................................................230
vi 8006k?avr?10/10 attiny24/44/84 27.9 rev c. 07/06 ..................................................................................................230 27.10 rev b. 05/06 ..................................................................................................230 27.11 rev a. 12/05 ..................................................................................................230 table of contents.......... ................. ................ ................. ................ ........... i
vii 8006k?avr?10/10 attiny24/44/84
8006k?avr?10/10 headquarters international atmel corporation 2325 orchard parkway san jose, ca 95131 usa tel: (+1)(408) 441-0311 fax: (+1)(408) 487-2600 atmel asia limited unit 01-5 & 16, 19f bea tower, millennium city 5 418 kwun tong road kwun tong, kowloon hong kong tel: (+852) 2245-6100 fax: (+852) 2722-1369 atmel munich gmbh business campus parkring 4 d-85748 garching b. munich germany tel: (+49) 89-31970-0 fax: (+49) 89-3194621 atmel japan 9f, tonetsu shinkawa bldg. 1-24-8 shinkawa chuo-ku, tokyo 104-0033 japan tel: (+81)(3) 3523-3551 fax: (+81)(3) 3523-7581 product contact web site www.atmel.com technical support avr@atmel.com sales contact www.atmel.com/contacts literature requests www.atmel.com/literature disclaimer: the information in this document is provided in connection with atmel products. no license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of atmel products. except as set forth in atmel?s terms and condi- tions of sale located on atmel?s web site, atmel assumes no li ability whatsoever and disclaims any express, implied or statutor y warranty relating to its products including, but not limited to, the implied warranty of merchantability, fitness for a particu lar purpose, or non-infringement. in no event shall atmel be liable for any direct, indirect, consequential, punitive, special or i nciden- tal damages (including, without limitation, damages for loss of profits, business interruption, or loss of information) arising out of the use or inability to use this document, even if atme l has been advised of the possibility of such damages. atmel makes no representations or warranties with respect to the accuracy or comp leteness of the contents of this document and reserves the rig ht to make changes to specifications and product descriptions at any time without notice. atmel does not make any commitment to update the information contained her ein. unless specifically provided otherwise, atmel products are not suitable for, and shall not be used in, automotive applications. atmel?s products are not int ended, authorized, or warranted for use as components in applications in tended to support or sustain life. ? 2010 atmel corporation. all rights reserved. atmel ? , logo and combinations thereof, and others ar e registered trademarks or trademarks of at mel corporation or its subsidiaries. o ther terms and product names may be trademarks of others.


▲Up To Search▲   

 
Price & Availability of ATTINY24V-10MUR

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X